Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Socket Java message exchange
    text
    copied!<p>I'm trying to make a communication between a PHP page and running Java server. Just a simple string exchange through sockets.</p> <p>This is my Java Code for thread that handles the connection:</p> <pre><code> InputStream in = clientSocket.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream())); String request; if((request=br.readLine())!=null){ System.out.println("got the following request: " + request); out.write(request +"\n"); out.flush(); out.close(); in.close(); } </code></pre> <p>I tested it with simple Java client that sends the string then receives the result and prints it back and it worked. Both client and the server had the same output.</p> <p>This is my PHP code:</p> <pre><code>$fp = @fsockopen ($host, $port, $errno, $errstr); if($fp){ fputs($fp, $str); //echo fgets($fp); } close($fp); </code></pre> <p>Which sends the string to the Server, and the Server receives it. But once I uncomment the line with fgets($fp) I am blocked until some sort of timeout happens after 1-2 minutes. During that Block my server is not receiving anything. After timeout my server prints, that it has received the line, and probably sends the response back, however, the PHP code doesn't print anything.</p> <p>What could be the problem?</p> <p>Thank you in advance.</p> <p>P.S. It is probably worth saying that I am accessing this web page through AJAX, so it "echoes" the result back to the other page.</p>
 

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