我正在尝试编写一个简单的客户端/服务器(客户端和服务器不是同一台机器),并且无法弄清楚如何给扭曲的IP地址。
from twisted.internet import protocol, reactor, endpoints
from twisted.protocols import basic
class FingerProtocol(basic.LineReceiver):
def lineReceived(self, user):
self.transport.write(self.factory.getUser(user) + b"\r\n")
self.transport.loseConnection()
class FingerFactory(protocol.ServerFactory):
protocol = FingerProtocol
def __init__(self, users):
self.users = users
def getUser(self, user):
return self.users.get(user, b"No such user")
fingerEndpoint = endpoints.serverFromString(reactor, ("192.168.1.7", "tcp:1079"))
fingerEndpoint.listen((FingerFactory({ b'moshez' : b'Happy and well'})))
reactor.run()
错误:
Traceback (most recent call last):
File "sensors/twistedTest.003.py", line 20, in <module>
fingerEndpoint = endpoints.serverFromString(reactor, ("192.168.1.7", "tcp:1079"))
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/endpoints.py", line 1724, in serverFromString
nameOrPlugin, args, kw = _parseServer(description, None)
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/endpoints.py", line 1635, in _parseServer
args, kw = _parse(description)
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/endpoints.py", line 1596, in _parse
for (type, value) in _tokenize(description):
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/endpoints.py", line 1570, in _tokenize
current += n
TypeError: can't concat bytes to tuple
如何给双绞线/电抗器一个IP地址?
答案 0 :(得分:1)
而不是使用(“ 192.168.1.7”,“ tcp:1079”)尝试b“ tcp:1079:interface = 192.168.1.7”。
赞:
fingerEndpoint = endpoints.serverFromString(reactor, b"tcp:1079:interface=192.168.1.7")
此外,地址“ 192.168.1.7”应该是服务器计算机上某些网络接口的地址。