Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sharing same local port in client UDP sockets

480 views
Skip to first unread message

Ganz

unread,
May 10, 2009, 5:57:39 AM5/10/09
to
I need to establish 2 different UDP session sockets in my client code (
directed to 2 different servers ) but sharing the same local port in both
sockets.
Is that possible in Windows?
Regards
Ganz


Remy Lebeau

unread,
May 11, 2009, 1:51:09 PM5/11/09
to

"Ganz" <gan...@gimail.com> wrote in message
news:e%236pv1U0...@TK2MSFTNGP02.phx.gbl...

> I need to establish 2 different UDP session sockets in my client code

> (directed to 2 different servers ) but sharing the same local port in


> both sockets. Is that possible in Windows?

Only if the two sockets are bound to different local IP addresses.
Otherwise, no, you would have to use different ports instead. Or, use a
single UDP socket and have it differentiate between the packets that it
recieves from each server. If nothing else, you can look at the IP/Port
that is sending each packet, if the packet data is too similar to
differentiate with.

--
Remy Lebeau (TeamB)


paul

unread,
May 12, 2009, 9:15:23 PM5/12/09
to

Yes. Have you tried this, what happens? Since the connection is
uniquely identified by the {local ip addr, local port, remote ip addr,
remote port} it should work since you have 2 different servers. If it
doesn't work you may need to set the SO_REUSEADDR option on the
sockets.

Remy Lebeau

unread,
May 13, 2009, 3:14:08 PM5/13/09
to

"paul" <pradhan...@gmail.com> wrote in message
news:2d81d4c3-b185-4cd9...@y6g2000prf.googlegroups.com...

> Yes. Have you tried this, what happens? Since the connection is
> uniquely identified by the {local ip addr, local port, remote ip addr,
> remote port} it should work since you have 2 different servers.

Except that you cannot have two server sockets bound and listening on the
same localip/localport pair at the same time.

> If it doesn't work you may need to set the SO_REUSEADDR
> option on the sockets.

If you use that, both servers can end up receiving each other's data.

--
Remy Lebeau (TeamB)


boris

unread,
May 14, 2009, 4:12:45 AM5/14/09
to

"paul" <pradhan...@gmail.com> wrote in message
news:2d81d4c3-b185-4cd9...@y6g2000prf.googlegroups.com...

>>>>Boris>>>>>>>>

This won't work for UDP (if UDP datagrams need to be sent from server to
client).
However, in case of TCP it will work just fine:
2 client TCP sockets are bound to same port and IP address (SO_REUSEADDR
option is used);
2 server tuples are different from each other.

Boris

0 new messages