Rajkumar S
Rajkumar S

Reputation: 2521

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 environment?

    create_socket (socket.AF_INET, socket.SOCK_STREAM)
    socket.setsockopt(socket.IPPROTO_IP, 24,1)                        
    socket.bind((clientip, 0))                         
    connect ((serverip,serverport))

Upvotes: 0

Views: 919

Answers (1)

Khue Vu
Khue Vu

Reputation: 3152

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

Upvotes: 3

Related Questions