View Single Post
Old 07-15-2009, 03:31 PM   #4 (permalink)
cad106uk
The Visitor
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
cad106uk is on a distinguished road
Default 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(selfreason):
        print 
"Lost a client!"
        
self.factory.clients.remove(self)

    
def lineReceived(selfline):
        print 
"received"repr(line)
        for 
c in self.factory.clients:
            
c.message(line)

    
def message(selfmessage):
        
self.transport.write(message '\n')


from twisted.internet import protocol
from twisted
.application import serviceinternet

factory 
protocol.ServerFactory()
factory.protocol MyChat
factory
.clients = []

application service.Application("chatserver")
internet.TCPServer(1025factory).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
cad106uk is offline  
Reply With Quote