title: Sending a message from PHP to Python through a socket
body: <p>I'm trying to send a message to a Python socket using PHP and that it prints the message.</p>
  
  <p>Here is the PHP code so far:</p>
  
  <pre><code>&lt;?
  $host = "localhost";
  $port = 12345;
  
  $f = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  socket_set_option($f, SOL_SOCKET, SO_SNDTIMEO, array('sec' =&gt; 1, 'usec' =&gt; 500000));
  $s = socket_connect($f, $host, $port);
  
  $msg = "message";
  $len = strlen($msg);
  
  socket_sendto($f, $msg, $len, 0, $host, $port);
  
  socket_close($f);
  ?&gt;
  </code></pre>
  
  <p>And here is the Python one:</p>
  
  <pre><code>#!/usr/bin/python
  # encoding: utf-8
  
  import socket
  
  s = socket.socket()
  host = "localhost"
  port = 12345
  s.bind((host, port))
  
  s.listen(5)
  while True:
     c, addr = s.accept()
     print s.recv(1024)
     c.close()
  </code></pre>
  
  <p>But I'm getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "server.py", line 15, in &lt;module&gt;
      print s.recv(1024)
  socket.error: [Errno 107] Transport endpoint is not connected
  </code></pre>
  
  <p>I've also tried with <code>socket_​sendmsg</code>, <code>socket_​write</code>, <code>fwrite</code> and many more, but the error in Python is always the same, <code>socket.error: [Errno 107] Transport endpoint is not connected</code>.</p>
  
  <p>It looks like I'm really lost.</p>
  
  <p>Could anyone help me?</p>
  
  <p>Thanks.</p>