I have a server written in Java. Its a simple one that echoes "HELLO" when a client connects and then echoes back any reply the client sends. The code is below:
ServerSocket ss=new ServerSocket(2001);
while(true) {
Socket s=ss.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out=new PrintWriter(s.getOutputStream(),true);
out.println("HELLO");
String msg=in.readLine();
out.println(msg);
}
I have a PHP script that connects to the server:
<?php
$socket=socket_create(AF_INET,SOCK_STREAM,getprotobyname('tcp'));
socket_connect($socket,'127.0.0.1',2001);
$msg=socket_read($socket,10);
echo socket_write($socket,'I am the client.');
$msg=socket_read($socket,20);
echo $msg;
?>
I am getting the "HELLO" message from the server, and the server is also getting the "I am the client" message, but the PHP client is not getting the reply back. What am I doing wrong here?