title: How to send and receive messages through a PHP socket in the same program
body: <p>I have written a simple socket program to send a message from client to server. That works fine and I need to get a response from  the server to client.
  Can I do it in a same socket program?If yes how can I do it?</p>
  
  <p>Here is my code for the server socket.</p>
  
  <pre><code>&lt;?php
  $address="127.0.0.1";
  $port="3222";
  $sock=socket_create(AF_INET,SOCK_STREAM,0) or die("Cannot create a socket");
  socket_bind($sock,$address,$port) or die("Couldnot bind to socket");
  socket_listen($sock) or die("Couldnot listen to socket");
  $accept=socket_accept($sock) or die("Couldnot accept");
  $read=socket_read($accept,1024) or die("Cannot read from socket");
  echo $read;
  </code></pre>
  
  <p>?></p>
  
  <p>Here is the code for Client socket.</p>
  
  <pre><code>&lt;?php
  $address="127.0.0.1";
  $port="3222";
  $msg="Hello server";
  
  $sock=socket_create(AF_INET,SOCK_STREAM,0) or die("Cannot create a socket");
  socket_connect($sock,$address,$port) or die("Could not connect to the socket");
  socket_write($sock,$msg);
  </code></pre>
  
  <p>?></p>
  
  <p>Can somebody help me please....</p>