PDA

View Full Version : Same port when you pass socketDescriptor?



Dumbledore
11th December 2007, 18:15
If you have a QTcpServer and you pass off a new connection to its own thread. Does this also communicate on some random port? Or is it the same port as the listener that this connection is established?

If it is a different port, how do you deal with firewalls?

wysota
11th December 2007, 20:05
If you have a QTcpServer and you pass off a new connection to its own thread. Does this also communicate on some random port? Or is it the same port as the listener that this connection is established?
It's a different port.


If it is a different port, how do you deal with firewalls?
You don't. Firewalls should track connections and pass such traffic that was established on another port. At least that's what the TCP protocol says :)

If you use iptables, a rule similar to:

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

should be present in the firewall for tcp traffic to work properly. If you're not a firewall admin, you needn't care.

Dumbledore
11th December 2007, 21:59
Wow, I didn't know that! My firewall is implemented through my router. So I imagine it is designed to follow the TCP specification and I needant worry?

wysota
11th December 2007, 22:03
Yes, that's correct. Otherwise you wouldn't be able to post on this forum :)

BTW. This is completely invisible for all the software - that's the intention of the mechanism. It's even hard to say the socket is related to any "port" - the server just gets another socket and it sort of works (the client still sees it as the port it connected to, but there is another socket listening on that port).