Hello,
I am using standard socket functions to send and receive data on a client/server model. I am using K-Develop under Ubuntu 10.04 OS. The application works fine locally but when I deploy it on my CentOS 5.5 server, data is not properly received by the server.
Whenever client sends more than 1000 bytes, the read() function on server side does not read all the data. Here is the server side code snippet.
Any idea?
Regards.
I am using standard socket functions to send and receive data on a client/server model. I am using K-Develop under Ubuntu 10.04 OS. The application works fine locally but when I deploy it on my CentOS 5.5 server, data is not properly received by the server.
Whenever client sends more than 1000 bytes, the read() function on server side does not read all the data. Here is the server side code snippet.
Code:
int sockfd, newsockfd, portno, clilen;
const int BUFFER_SIZE = 1024 * 3;
char buffer[BUFFER_SIZE];
struct sockaddr_in serv_addr, cli_addr;
int yes = 1;
portno = 12345;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR in opening socket...\n");
else
printf("Socked opened successfully...\n");
if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1)
{
error("Setsockopt error...");
exit(1);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
error("ERROR in binding...\n");
exit(1);
}
else
printf("Socked binded successfully...\n");
if( listen(sockfd,5) < 0 )
printf("Error in listening...\n");
else
printf("Server has started listening...\n");
printf("Waiting for connections on port %d...\n",portno);
while (true)
{
int n = 0;
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,(struct sockaddr *)&cli_addr,(socklen_t*)&clilen);
if (newsockfd < 0)
{
error("ERROR in accepting connection...");
continue;
}
else
printf("Connected accepted.\n");
bzero(buffer,BUFFER_SIZE);
n = read(newsockfd,buffer,sizeof(buffer));
printf("Bytes read: %d\n",n);
Regards.
Comment