我如何给扭曲的服务器一个IP地址?

How do I give twisted server an ip address?

我正在尝试编写一个简单的 client/server(其中客户端和服务器不是同一台机器)并且不知道如何提供扭曲的 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

如何给 twisted/reactor 一个 IP 地址?

而不是使用 ("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”应该是服务器计算机上某些网络接口的地址。