Note that there are some explanatory texts on larger screens.

plurals
  1. POC socket programming: client send() but server select() doesn't see it
    text
    copied!<p>I have a server and a client running on two different machines where the client <code>send()</code>s but the server doesn't seem to receive the message. The server employs <code>select()</code> to monitor sockets for any incoming connections/messages. I can see that when the server accepts a new connection, it updates the <code>fd_set</code> array but always returns 0 despite the client <code>send()</code> messages. The connection is TCP and the machines are separated by like one router so dropping packets are highly unlikely.</p> <p>I have a feeling that it's not <code>select()</code> but perhaps <code>send()</code>/<code>sendto()</code> from client that may be the problem but I'm not sure how to go about localizing the problem area.</p> <pre><code> while(1) { readset = info-&gt;read_set; ready = select(info-&gt;max_fd+1, &amp;readset, NULL, NULL, &amp;timeout); </code></pre> <p>}</p> <p>above is the server side code where the server has a thread that runs <code>select()</code> indefinitely.</p> <pre><code>rv = connect(sockfd, (struct sockaddr *) &amp;server_address, sizeof(server_address)); printf("rv = %i\n", rv); if (rv &lt; 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 &lt; 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, &amp;server_address, sizeof(server_address)); if (rv &lt; 0) printf("MAIN: ERROR sendto() %i: %s\n", errno, strerror(errno)); printf("MAIN: rv is %i\n", rv); </code></pre> <p>and this is the client side where it connects and sends messages and returns</p> <pre><code>connected MAIN: rv is 4 MAIN: rv is 4 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload