asdvawe
asdvawe

Reputation:

Socket programming

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?

Upvotes: 0

Views: 430

Answers (1)

Tzury Bar Yochay
Tzury Bar Yochay

Reputation: 9004

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

Upvotes: 2

Related Questions