views:

118

answers:

1

I have a server application that binds to a port and listens on it. I've set up the router to forward the data on this port to the server.

Now, on the client side, I don't actually bind() the socket to any port, and I usually end up with a different port everytime. In that case, how can I prepare the router to forward that port to the client? Or am I supposed to use bind() with the client socket as well? (I remember reading that you're not supposed to do that.)

+2  A: 

Firewalls are usually stateful - meaning if TCP connection request into the protected network is allowed, then the packets back to the client are matched (and passed through) automatically. That is to say you don't worry about the client, just setup port forwarding to the server app.

Nikolai N Fetissov
Agreed. Routers know the details of outbound connections from a client socket (even a pre-bound one), and thus can automatically route inbound packets for that connection back to the correct PCs. That is what a router is supposed to do. New inbound connections for a server socket, on the other hand, do not have those routing details known until a connection is established with a client. That is why extra forwarding rules are necessary on the server side so that the initial connection reaches the correct server PC and the router can then track the resulting connection afterwards.
Remy Lebeau - TeamB
No, total bull. Take a look here http://en.wikipedia.org/wiki/Stateful_firewall
Nikolai N Fetissov
So all routers today have stateful firewalls?
Meta
I didn't say all, but most consumer-grade things you'd pick up in BestBuy run some crippled version of Linux with a simple stateful firewall.
Nikolai N Fetissov