Skip to content Skip to sidebar Skip to footer

Setsockopt Before Connect For Reactor.connectTCP

I have a small python client which needs a setsockopt after create_socket, but before connect. The non-twisted python code is as follows. How can this be expressed in a twisted env

Solution 1:

In twisted you can use the reactor.adoptStreamPort:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setsockopt(socket.IPPROTO_IP, 24,1) 
s.bind((serverip, serverport))    
s.listen(1)
port = reactor.adoptStreamPort(
       s.fileno(), AF_INET, YourFactory())

I don't really understand your code if you are building a listen socket or connect socket. I assume it is a listen socket. More details can be found here: http://twistedmatrix.com/documents/12.2.0/api/twisted.internet.interfaces.IReactorSocket.html


Post a Comment for "Setsockopt Before Connect For Reactor.connectTCP"