I'm trying to send a message to a Python socket using PHP and that it prints the message.
Here is the PHP code so far:
<?
$host = "localhost";
$port = 12345;
$f = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($f, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1, 'usec' => 500000));
$s = socket_connect($f, $host, $port);
$msg = "message";
$len = strlen($msg);
socket_sendto($f, $msg, $len, 0, $host, $port);
socket_close($f);
?>
And here is the Python one:
#!/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()
But I'm getting the following error:
Traceback (most recent call last):
File "server.py", line 15, in <module>
print s.recv(1024)
socket.error: [Errno 107] Transport endpoint is not connected
I've also tried with socket_sendmsg
, socket_write
, fwrite
and many more, but the error in Python is always the same, socket.error: [Errno 107] Transport endpoint is not connected
.
It looks like I'm really lost.
Could anyone help me?
Thanks.