title: php socket sending XML
body: <p>I have been trying to send this XML block to a device, but no luck.  If I use wireshark it appears to be sending but its like I am missing one little thing, carriage return or something.  I have posted the xml needing to be send and my PHP code.  Any ideas?  Sorry I am new to PHP.</p>
  
  <pre><code>&lt;c4soap name="SendToDeviceAsync" async="True"&gt;
  &lt;param name="iddevice" type="number"&gt;14&lt;/param&gt;
  &lt;param name="data" type="string"&gt;
  &lt;devicecommand owneridtype="" owneriditem="-1"&gt;
  &lt;command&gt;SET_LEVEL&lt;/command&gt;
  &lt;params&gt;
  &lt;param&gt;
  &lt;name&gt;LEVEL&lt;/name&gt;
  &lt;value type="INTEGER"&gt;
  &lt;static&gt;10&lt;/static&gt;
  &lt;/value&gt;
  &lt;/param&gt;
  &lt;/params&gt;
  &lt;/devicecommand&gt;
  &lt;/param&gt;
  &lt;/c4soap&gt;
  </code></pre>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
  
  $host = "192.168.0.210";
  $port = 5020;
  
  $package[0]  = "&lt;c4soap name=\"SendToDeviceAsync\" async=\"True\"&gt;";
  $package[1]  = "&lt;param name=\"iddevice\" type=\"number\"&gt;14&lt;/param&gt;";
  $package[2]  = "&lt;param name=\"data\" type=\"string\"&gt;";
  $package[3]  = "&lt;devicecommand owneridtype=\"\" owneriditem=\"-1\"&gt;";
  $package[4]  = "&lt;command&gt;SET_LEVEL&lt;/command&gt;";
  $package[5]  = "&lt;params&gt;";
  $package[6]  = "&lt;param&gt;";
  $package[7]  = "&lt;name&gt;LEVEL&lt;/name&gt;";
  $package[8]  = "&lt;value type=\"INTEGER\"&gt;";
  $package[9]  = "&lt;static&gt;100&lt;/static&gt;";
  $package[10] = "&lt;/value&gt;";
  $package[11] = "&lt;/param&gt;";
  $package[12] = "&lt;/params&gt;";
  $package[13] = "&lt;/devicecommand&gt;";
  $package[14] = "&lt;/param&gt;";
  $package[15] = "&lt;/c4soap&gt;";
  
  $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 
  
  echo "Attempting to connect to '$host' on port '$port'...&lt;br&gt;\n";
  
  $result = socket_connect($sock, $host, $port);
  
  if ($result === false) {
      $socketError  = socket_last_error($sock);
      $socketString = socket_strerror($socketError);
      $resultString = var_export($result, 1);
      echo "socket_connect() failed.&lt;br&gt;\n",
           "Reason: ($resultString) ", $socketString, "&lt;br&gt;\n";
  }
  
  echo "Sending XML...&lt;br&gt;\n";
  
  foreach ($package as $onePackage)
  {
      $buffer = $onePackage . "\n";
      $bufferLength = strlen($buffer);
      socket_write($sock, $buffer, $bufferLength);
  }
  
  socket_close($sock);
  
  echo "Completed sending!&lt;br&gt;\n";
  </code></pre>