07-15-2009, 03:31 PM
|
#4 (permalink)
|
|
The Visitor
Join Date: Jul 2009
Posts: 3
Thanks: 0
|
Also having a problem with socket based php communication with a python server
Hi
I am hoping someone has some insight into what is happening here. I am also writing a php script to connect to a python server. I have written a simple twisted telnet server (taken from the twisted tutorial) and a simple php client which writes to it. In the logs I can see the PHP client connecting to the server and disconnecting from the twisted server but none of the fwrite commands ever register in the server logs (or anywhere else on the twisted server). However I do not get an error in the PHP script, the fwrite function returns as though the function ran without errors.
the twisted server
PHP Code:
"""The most basic chat protocol possible.
run me with twistd -y chatserver.py, and then connect with multiple
telnet clients to port 1025
"""
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
def connectionMade(self):
print "Got new client!"
self.factory.clients.append(self)
def connectionLost(self, reason):
print "Lost a client!"
self.factory.clients.remove(self)
def lineReceived(self, line):
print "received", repr(line)
for c in self.factory.clients:
c.message(line)
def message(self, message):
self.transport.write(message + '\n')
from twisted.internet import protocol
from twisted.application import service, internet
factory = protocol.ServerFactory()
factory.protocol = MyChat
factory.clients = []
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
The php client
PHP Code:
<?php
$fp = fsockopen("localhost", 1025, $errnum, $errstr);
if ($fp) {
$tmp = "This is a test";
print $tmp;
print fwrite($fp, $tmp);
}
fclose($fp);
?>
Does anyone have any idea as to where the data from the fwrite function is going?
Thanks
|
|
|
|