Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Troubleshoot TCP Socket Crashing?

0 views
Skip to first unread message

aquat...@gmail.com

unread,
May 1, 2006, 12:17:38 PM5/1/06
to
I am working on a simple client-server project that uses UNIX TCP/IP
sockets. The programs are written in C and are adapted from an
earlier, working project.

The client sends a string to the server and waits for a response.
Here's a snip of the client code:

<snip>
rc = send(socket_fd, &msg, (size_t)sizeof(msg),0);

printf("send: rc = %i\n", rc);

if (rc < 0){
perror("receiveMessage:write");
exit(-1);
}

rc = recv(socket_fd, in_buf, sizeof(in_buf),0);

printf("recv: rc = %i\n",rc);
printf("sizeof(in_buf) = %i\n",sizeof(in_buf));
printf("in_buf = %s\n",in_buf);
<snip>

Send() appears to work correctly - it returns 398 (the size of the
string) and the string is received by the server.

Both msg and in_buf are char strings set to a length of 398.

However, recv() immediately returns 0 (the server hasn't responded yet
and doesn't until a set number of clients connects to it), which I
believe indicates a problem with the socket. The output of the printf
statements look like this:

**** sendServer ****
Sending: REG^arlette^8500^1^_^_^_^_^_^_^
send: rc = 398
recv: rc = 0
sizeof(in_buf) = 398
in_buf = Lè¿¿O("(¬ï(

**** sendServer ****

I have read the man pages for send(), recv(), socket(), and have
googled through this group, but haven't found any suggestion on how to
troubleshoot a problem like this (probably because it's trivial).

Hope someone can pass on some advice on what I can do to troubleshoot
this problem.

TIA,

Jim

aquat...@gmail.com

unread,
May 1, 2006, 2:32:15 PM5/1/06
to
I figured out what I was doing wrong.

I was closing the socket on the server side with close() after
receiving the message from the client, breaking the connection with the
client.

Jim

0 new messages