title: Use PHP socket to send and receive data
body: <p>I'm trying to send and receive data by PHP socket.</p>
  
  <p>Evrything is OK but when I'm trying to send data PHP does not send anything (Wireshark told me that sent data length was 0).</p>
  
  <p>I'm using this code:</p>
  
  <pre><code>&lt;?php
  $address = 'example.com';
  $port = 1234;
  
  $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  $sockconnect = socket_connect($sock, $address, $port);
  
  $c = 0;
  do {
      $c++;
      $msg = '&lt;test&gt;Xml data&lt;/test&gt;';
  
      socket_write($sock, $msg, strlen($msg));
  
      echo socket_read($sock, 1024 * 100, PHP_NORMAL_READ);
  
  } while ($c &lt; 3);
  
  socket_close($sock);
  </code></pre>
  
  <p>Can anyone help me?
  Thanks for reading my question.</p>