Twisted Framework 服务器作为客户端建立连接?

Twisted Framework Server Making Connections as a Client?(Twisted Framework 服务器作为客户端建立连接?)
本文介绍了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:UsersSa'idDocumentsLearning ProgrammingPythonCore Python Application ProgrammingChapter 2 - Network ProgrammingTwisted	wisted_intro.py", line 9, in <module>
    from twisted.internet import reactor
  File "C:Python27libsite-packages	wistedinternet
eactor.py", line 39, in <module>
    default.install()
  File "C:Python27libsite-packages	wistedinternetselectreactor.py", line 196, in install
    reactor = SelectReactor()
  File "C:Python27libsite-packages	wistedinternetselectreactor.py", line 72, in __init__
    posixbase.PosixReactorBase.__init__(self)
  File "C:Python27libsite-packages	wistedinternetase.py", line 499, in __init__
    self.installWaker()
  File "C:Python27libsite-packages	wistedinternetposixbase.py", line 286, in installWaker
    self.waker = self._wakerFactory(self)
  File "C:Python27libsite-packages	wistedinternetposixbase.py", line 81, in __init__
    client.connect(server.getsockname())
  File "C:Python27libsocket.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 版本之间的差异,因此它使用套接字对.创建此套接字对涉及连接回 localhost,因此,某些过于激进的防火墙配置可能会触发此区域.

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 服务器作为客户端建立连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)