C socket programming: client send() but server select() doesn't see it

Posted by Fantastic Fourier on Stack Overflow See other posts from Stack Overflow or by Fantastic Fourier
Published on 2010-04-17T19:44:41Z Indexed on 2010/04/17 19:53 UTC
Read the original article Hit count: 269

Filed under:
|
|
|
|

Hey all, I have a server and a client running on two different machines where the client send()s but the server doesn't seem to receive the message. The server employs select() to monitor sockets for any incoming connections/messages. I can see that when the server accepts a new connection, it updates the fd_set array but always returns 0 despite the client send() messages. The connection is TCP and the machines are separated by like one router so dropping packets are highly unlikely.

I have a feeling that it's not select() but perhaps send()/sendto() from client that may be the problem but I'm not sure how to go about localizing the problem area.

    while(1)
{
    readset = info->read_set;   
    ready = select(info->max_fd+1, &readset, NULL, NULL, &timeout);

}

above is the server side code where the server has a thread that runs select() indefinitely.

rv = connect(sockfd, (struct sockaddr *) &server_address, sizeof(server_address));
printf("rv = %i\n", rv);
if (rv < 0)
{
    printf("MAIN: ERROR connect() %i:  %s\n", errno, strerror(errno));
    exit(1);
}
else
    printf("connected\n");

sleep(3);

char * somemsg = "is this working yet?\0";
rv = send(sockfd, somemsg, sizeof(somemsg), NULL);
if (rv < 0)
    printf("MAIN: ERROR send() %i:  %s\n", errno, strerror(errno));
printf("MAIN: rv is %i\n", rv);
rv = sendto(sockfd, somemsg, sizeof(somemsg), NULL, &server_address, sizeof(server_address));
if (rv < 0)
    printf("MAIN: ERROR sendto() %i:  %s\n", errno, strerror(errno));
printf("MAIN: rv is %i\n", rv);

and this is the client side where it connects and sends messages and returns

connected
MAIN: rv is 4
MAIN: rv is 4

any comments or insightful insights are appreciated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about unix