Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I must of have done something wrong, I have added the size to the header message and now am not receiving any data fro both client and server. Am using it correctly. Here is part of the code where i inserted size.</p> <p>SERVER</p> <pre><code>if(fork()) { printf("\n Server listening to clients on port 2000"); printf("\n Server got request from%s",inet_ntoa(client.sin_addr)); bzero(buf,256); printf("\n SEND DATA&lt;q or Q to quit&gt; :%s",buf); scanf("%s",buf); while((strcmp(buf,"q")!=0)&amp;&amp;(strcmp(buf,"Q")!=0)) { int size = htonl(strlen(buf)+1); send(new_sd,size,sizeof(size),0); send(new_sd,buf,size,0); scanf("%s",buf); } send(new_sd,"q",5,0); } else{ int size; recv(new_sd,size,sizeof(size),0); size=ntohl(size); n=recv(new_sd,buf,size,0); while((strcmp(buf,"q")!=0)&amp;&amp;(strcmp(buf,"Q")!=0)) { printf("\nRECEIVED DATA =%s",buf); n = recv(new_sd,buf,size,0); } printf("\n Bye"); send(new_sd,"EOF",BUFLEN,0); close(sd); close(new_sd); } } return 0; } </code></pre> <p>CLIENT</p> <pre><code>if(fork()) { printf("\n SEND DATA&lt;q or Q to quit&gt; :%s",rbuf); scanf("%s",rbuf); while((strcmp(rbuf,"q")!=0)&amp;&amp;(strcmp(rbuf,"Q")!=0)) { int size = htonl(strlen(sbuf)+1); send(sd,size,sizeof(size),0); send(sd,sbuf,size,0); scanf("%s",sbuf); } send(sd,"q",5,0); } else{ int size; recv(sd,size,sizeof(size),0); size = ntohl(size); recv(sd,rbuf,size,0); while((strcmp(rbuf,"q")!=0)&amp;&amp;(strcmp(rbuf,"Q")!=0)) { printf("\nRECEIVED DATA =%s",rbuf); //n = recv(sd,rbuf,bytes_to_read,0); } printf("\n Bye"); send(sd,"EOF",4,0); close(sd); } return 0; } </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