tags:

views:

115

answers:

1

Hi everyone:

Please take a look at my code:

from twisted.internet.protocol import ServerFactory
from twisted.internet import reactor
from twisted.protocols import basic


class ThasherProtocol(basic.LineReceiver):
    def lineReceived(self, line):
        print line
        self.transport.write( 1 )
        self.transport.loseConnection()



class ThasherFactory(ServerFactory):
    protocol = ThasherProtocol 


reactor.listenUNIX( "/home/disappearedng/Desktop/test.sock" , ThasherFactory() )
reactor.run()



===


import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM )
s.connect( "/home/disappearedng/Desktop/test.sock")
s.sendall('hello')
print s.recv(4096)
# Hangs

Why does it hang? Why doens't it return 1?

+2  A: 

you should send a line and not just hello in order to have lineReceived called e.g. s.sendall('hello\r\n')

Tzury Bar Yochay
thxman yeah I figured that out after reading the API
@adswave, so accept this answer (use the checkmark icon under the big number to the left of the answer).
Alex Martelli