Twisted Framework服务器以客户端身份建立连接吗? [英] Twisted Framework Server Making Connections as a Client?

查看:101
本文介绍了Twisted Framework服务器以客户端身份建立连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,首先,让我向您展示我的代码及其返回的错误:

So first off, let me show you my code and the error it returns:

print "before import"
from twisted.internet import protocol #  imports
print "after protocol"
from twisted.internet import reactor
print "after reactor"
from twisted.internet.endpoints import TCP4ServerEndpoint
print "after import"

class Echo(protocol.Protocol):
    """docstring for Echo"""
    def connectionMade(self):
        cADDR = self.clnt = self.transport.getPeer().host
        print "...Connection made with {0}".format(cADDR)
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    """docstring for EchoFactory"""
    def buildProtocol(self, addr):
        return Echo()


server = TCP4ServerEndpoint(reactor, 45002)
server.listen(EchoFactory())
reactor.run()

如您所见,我创建了一些打印语句来准确调试导致问题的导入.现在针对错误:

As you can see, I created some print statements to debug exactly which import is causing the issue. Now for the error:

before import
after protocol
Traceback (most recent call last):
  File "C:\Users\Sa'id\Documents\Learning Programming\Python\Core Python Application Programming\Chapter 2 - Network Programming\Twisted\twisted_intro.py", line 9, in <module>
    from twisted.internet import reactor
  File "C:\Python27\lib\site-packages\twisted\internet\reactor.py", line 39, in <module>
    default.install()
  File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 196, in install
    reactor = SelectReactor()
  File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 72, in __init__
    posixbase.PosixReactorBase.__init__(self)
  File "C:\Python27\lib\site-packages\twisted\internet\base.py", line 499, in __init__
    self.installWaker()
  File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
    self.waker = self._wakerFactory(self)
  File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 81, in __init__
    client.connect(server.getsockname())
  File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
>>> 

由于某种原因,我的Twisted服务器试图建立连接,实际上,它应该是等待连接而不是建立连接的服务器.从错误中您可以看到,它在reactor导入之前打印,而不是在导入之后打印,因此reactor确实是这里的问题.我将其发布在另一个网站上并没有获得很大的成功,但是答复者说,这是因为反应堆正在尝试设置_SocketWaker,并且某些东西阻止了它的设置.他说,关闭防火墙可以使其正常工作,但是尝试使用防火墙后,会返回相同的错误.请注意,我托管此Echo()服务器的端口是转发端口,因此该端口可能不是问题.任何输入将不胜感激.

For some reason, my Twisted server is trying to make connections, when in reality, it should be the one waiting for the connections, not making them. And as you can see from the error, it prints right before the reactor import, but not after it, so the reactor is really the issue here. I've posted this on another website without much success, but the replier said that, it was because the reactor was trying to setup a _SocketWaker and something was blocking it from setting it up. He said that turning off your firewall would make it work, but after trying it, the same error was returned. Just a note, the port I am hosting this Echo() server on is port forwarded, so the port is probably not the issue. Any input would be much appreciated.

谢谢.

推荐答案

在UNIX上,Twisted使用管道设置了线程密集的文件描述符.但是,在Windows上,匿名管道存在多个实现问题,并且不同Windows版本之间存在差异,因此它使用套接字对.创建此套接字对涉及重新连接到本地主机,因此,某些过于激进的防火墙配置可能会触发该区域.

On UNIX, Twisted sets up a thread-waker file descriptor using a pipe. However, on Windows, anonymous pipes have several implementation issues and discrepancies between different Windows versions, so it uses a socket pair. Creating this socket pair involves connecting back to localhost, so, certain overly-aggressive firewall configurations can trigger this area.

这篇关于Twisted Framework服务器以客户端身份建立连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆