Data not received by twisted socket connection
我有一个扭曲的服务器脚本,在unix套接字上监听,当客户端处于扭曲状态时,它将接收数据,但是如果我通过香草python套接字代码发送数据,它将无法正常工作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class SendProtocol(LineReceiver): """ This works """ def connectionMade(self): print 'sending log' self.sendLine(self.factory.logMessage) if __name__ == '__main__': address = FilePath('/tmp/test.sock') startLogging(sys.stdout) clientFactory = ClientFactory() clientFactory.logMessage = 'Dfgas35||This is a message from server' clientFactory.protocol = SendProtocol port = reactor.connectUNIX(address.path, clientFactory) reactor.run() |
但这不会(服务器未获取任何数据)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock_addr = '/tmp/test.sock' try: sock.connect(sock_addr) except socket.error, msg: print >> sys.stderr, msg sys.exit(1) sock.setblocking(0) # not needed though tried both ways print 'connected %s' % sock.getpeername() print 'End END to abort' while True: try: line = raw_input('Enter mesg: ') if line.strip() == 'END': break line += '\ ' print 'sending' sock.sendall(line) finally: sock.close() |
您的两个客户端程序发送不同的数据。一个发送
\
\