Note that there are some explanatory texts on larger screens.

plurals
  1. POBufferedReader readLine remains blocked when using C client and Java server
    text
    copied!<p>I am currently working on a C client(A) which will communicate with a Java server(B), who is a client for a RMI server(C). A has to send its arguments to B which will send them to C, C will process them, resend them back to B and B will return them to A. So clearly A has to write to the socket and then remain blocked until B sends something back. The problem I am facing is that after A writes to the socket and remains blocked by select(), B is not unblocked from its own readLine.</p> <p>If I remove the select() and read() from A, everything will work perfectly. Here's the code</p> <p>A-client.c</p> <pre><code> int err; err = send(sockfd,(const char*)toSend,size,0);//send counter if (err &lt; 0){ perror("Problem encountered while sending"); exit(3); } //it always gets past this line fd_set read_set; int nb; FD_ZERO(&amp;read_set); //initialize variables for select FD_SET(sockfd, &amp;read_set); nb = select(sockfd+1, &amp;read_set, NULL, NULL, NULL); if (nb!=0){ if (FD_ISSET(sockfd, &amp;read_set)) {//if data is incoming from*/ char word[4096]=""; if (read(sockfd, word, 4096) == 0){ perror("The server terminated prematurely"); exit(4); } for (i=0;i&lt;4096;i++){ printf("%c",word[i]); } } } </code></pre> <p>B-server.Java</p> <pre><code>connection = socket1.accept(); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); //it always passes this line String str = br.readLine(); //it passes this line only if i kill the C client or remove the read and select from the client String[] splitStr = str.split("\\s+"); int argsLen = splitStr.length; </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