1
votes

first - it's not a question of "how to bind to port of another software".

now, i have a client-server app, based on TCP and i'd like to make it UDP, but i'm missing something..

i have 2 rules (which i put) to this app:
1) the "server" can stay behind router without any port forwarding configuration.
2) the "client" can listen to only one port.

in TCP i do it like this:
1) the server opens initial connection to the client on port X.
2) when the client wants to open communication channel to the server it uses the initial socket to ask the server for a new one.
3) the server creates a new socket and connect to the client on port X. 4) the client accept this new connection on port X, and now the client talk with the server on this new socket.

this way i can have multiple connections on the same port.

in UDP, i have a little problem..
1) the server sends the initial connection dgram to the client on port X.
2) when the client wants to open communication channel to the server it sends request for a new socket to the initial socket's addr.
3) the server receives the message, creates a new udp socket, and use it to send data to the client on port X.
4) the client receives the new dgram, and ....?

basically what i want to happen now is to "accept" this connection. meaning: to create a new UDP socket, to bind it also to port X and receive data only from that specific incoming socket addr (ip,port). but i cannot do that because i can't bind multiple socket to same port.
so what is the way to create multiple udp connections on one port? (in networking way, not just create a ring buffer of dgrams and send to the right socket)

thanks :)

1
You can't have "connection" with UDP because UDP is not a "connected" protocol but datagram protocol.sfk
and i did was very careful not to say the "connection" word in the UDP matter. when i say "connection" i mean to open a gate for answering.. so what i want is just the server side (which is blocked from outside) to sends a UDP dgram to the client, so the client could later on send dgram to that socket, and receive dgrams from only that specific socket (like tcp accept) it was possible, if i could bind a new socket on the same port, and receive data only from the (ip,port) that i want.RoeeK
@sfk Despite UDP being stateless protocol, connect() call does influence socket operations in a major way. For instance, on FreeBSD, you can't get errors (like ICMP destination unreachable) from UDP socket unless it's connected.WGH

1 Answers

4
votes

As UDP is connectionless protocol, on step 4 you check the contents of UDP message and decide how to handle it. In other words, the type of message is defined only by it's contents.

However, I have a feeling that your whole design is a bit wrong. It's much more common for the client to be behind firewall (just because there exist more clients, than servers). If you need to put the server behind firewall, you just configure the firewall to allow connections to the set of ports. Even when you have just one more port opened, nothing prevents the client from connecting to the same server port several times in parallel.