|
-
February 12th, 2009, 12:16 PM
#1
Client/server problem; server either stops receiving data or client stops sending
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:
Code:
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:
Code:
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:
Code:
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?
-
February 12th, 2009, 12:46 PM
#2
Re: Client/server problem; server either stops receiving data or client stops sending
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.
-
February 12th, 2009, 03:19 PM
#3
Re: Client/server problem; server either stops receiving data or client stops sending
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:
Code:
bytesSent = send(m_socket, recvbuf, strlen(recvbuf), 0);
-
February 15th, 2009, 05:35 PM
#4
Re: Client/server problem; server either stops receiving data or client stops sending
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.
-
February 23rd, 2009, 07:15 AM
#5
Re: Client/server problem; server either stops receiving data or client stops sending
As someone said, your client expects to receive data. And since the server are not sending anything, the client recv will block.
"The making of software, like the making of sausages, should never be watched."
http://blog.gauffin.org - .NET Coding/Architecture
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|