Python 套接字编程

Python 套接字编程,python,sockets,Python,Sockets,请看一下我的代码: 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.tran

请看一下我的代码:

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

为什么要挂起来?为什么它不返回1

要让LineReceive接听电话,你应该发送一条线路,而不仅仅是hello e、 g.
s.sendall('hello\r\n')