Note that there are some explanatory texts on larger screens.

plurals
  1. POTCP connection. How to make the client only send data at the moment of the server's read()?
    primarykey
    data
    text
    <p>I have a client in iPod iOS 4.3 and a server in Linux C. I can make a TCP connection and transfer data. </p> <p>The server runs in a cycle with read() and printf.The client should send data only when asked. I found out that even after one read(), printf and halting at a getchar(), the client (iPod) is still getting the messagem <em>NSStreamEventHasSpaceAvailable</em> and sends the data. </p> <p>After i press any key on the server, it gets to the read() again, and shows much more data. I just wanted some help about the synchronous/asynchronous and blocking/non-blocking setting i should use in both the client and server. (theoretical, thus no need for coding, i guess.)</p> <p>As requested, here is the server code:</p> <pre><code>void testApp::setup() { int portno; struct sockaddr_in serv_addr; socklen_t clilen; connection = 0; //Still no connection sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd &lt; 0) error("ERROR opening socket"); bzero((char *) &amp;serv_addr, sizeof(serv_addr)); portno = atoi("50000"); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(sockfd, (struct sockaddr *) &amp;serv_addr,sizeof(serv_addr)) &lt; 0) error("ERROR on binding"); listen(sockfd,5); } void testApp::update() { int check = 0; int n; char buffer[256]; if(connection != 0) { check = recv(newsockfd, buffer, 256, MSG_PEEK|MSG_DONTWAIT); } /* developerweb.net/viewtopic.php?id=5627 */ if(connection == 0 /*1st connection*/ | check == 0 | (check &lt; 0 &amp;&amp; errno != EAGAIN)) { printf("CHECK é %d",check); if(connection != 0) { close(newsockfd); newsockfd = -1; printf("Client disconnected.\n");} printf("\n\n-=Waiting for connection...=-\n"); newsockfd = accept(sockfd,(struct sockaddr *) &amp;cli_addr,&amp;clilen); printf("\nClient connected successfuly! \n"); } if (newsockfd &lt; 0) {printf("ERROR on accept"); close(newsockfd); newsockfd=-1; } else if(newsockfd == 0) printf("No socket\n"); else { printf("Waiting for message...\n"); connection = 1; bzero(buffer,256); n = read(newsockfd,buffer,255); if (n &lt; 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); } printf("\nPress any key to continue..."); getchar(); } </code></pre> <p>Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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