Click to See Complete Forum and Search --> : Client/server problem; server either stops receiving data or client stops sending


knobody
February 12th, 2009, 11:16 AM
I have a client program running on Unix which creates a socket and connects to a server program running on a Windows machine, then starts performing operations which produce constantly changing double values. I use a timer, and every 5 milliseconds I call a function which takes whatever my value is at that time, converts it to a string, and sends it to the second computer. The server program receives the value from the client and prints to the screen.

The client and server successfully connect, and initially the sending and receiving works. But after a short time, the server's print messages to the screen slow down, and then the messages showing the new values stop altogether.

On the client side program, here's the function I call to connect to the server:


if ((ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))<0)
{
perror("Client-socket() error");
}
else
printf("Client: socket() is OK.\n");


clientService.sin_family = AF_INET;
clientService.sin_port = htons(55555);
clientService.sin_addr.s_addr = inet_addr("198.9.200.2");

if (connect(ConnectSocket, (struct sockaddr *)&clientService, sizeof(clientService)) < 0)
{
printf("Client: Failed to connect.\n");
close(ConnectSocket);
exit(-1);
}
else
printf("Client: connect() is OK.\n");


printf("Client: Connected to server...\n");

}


and for this the function called every 5 milliseconds by the client to send data:

int bytesRecv;
int bytesSent;
char recvbuf[200] = "";
char sendbuf1[200];
// convert data to string then send
sprintf(sendbuf1,"%20.4f",val);
//sending
send(ConnectSocket, sendbuf1, strlen(sendbuf1), 0);


bytesRecv = recv(ConnectSocket, recvbuf, 32, 0);

if(bytesRecv < 0)
{
perror("Client-read() error");
close(ConnectSocket);
exit(-1);
}

else if (bytesRecv == 0)

{

printf("Server program has issued a close()\n");

close(ConnectSocket);

exit(-1);

}


And for the server, this is the part of the code I use for receiving the data:


for(;;) {
/* wait for client’s message */
bytesRecv = recv(socket, recvbuf, 200, 0);

printf("value received: %s\n",recvbuf);
if (bytesRecv == SOCKET_ERROR)
{
printf("Server: recv() error %ld.\n", WSAGetLastError());
exit(-1);
}

Does anyone have an idea what could be wrong, or what I could do to check for what is wrong?

Richard.J
February 12th, 2009, 11:46 AM
to verify that your client continues to send, use wireshark as a network monitor.

One thing looks a bit strange: why do you call recv() in your client? You did not mention that your server sends back anything.

knobody
February 12th, 2009, 02:19 PM
Thanks, wireshark looks like it could be of some help.

I just didn't notice that I hadn't copied all line sof code from my server snippet. Here's what I do for sending from the server:

bytesSent = send(m_socket, recvbuf, strlen(recvbuf), 0);

knobody
February 15th, 2009, 04:35 PM
From using wireshark, I see that I have a zerowindow problem. Any chance somebody knows where I can find a solution to that? So far I'm coming up empty.

verifier
February 23rd, 2009, 06:15 AM
As someone said, your client expects to receive data. And since the server are not sending anything, the client recv will block.