Reputation: 476
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
>>>
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.
Thanks.
Upvotes: 2
Views: 286
Reputation: 31860
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.
Upvotes: 1