Retrieve UDP Server Port

If I setup a listening port with…
udpSocket = SDLNet_UDP_Open(0);

How can I find what port was actually opened?
I have tried…
tempIPAddress = SDLNet_UDP_GetPeerAddress(udpSocket, -1);
But as reported in docs it only returns info on the port that was specified
with SDLNet_UDP_Open(port);

Im really just after the port number. Any ideas would be greatly
appreciated.
I know gethostname will get the IP, but this is not a part of SDL_net :frowning:

Regards,

Si.

I had this problem once myself and I was not able to resolve it in an
elegant way by just using the means provided by SDL_net. My workaround
was to send a packet from my opened UDP socket with unknown port
number to another UDP socket with a known port number (in my case this
was a remote socket but it should work with a local socket too). After
the reception of the packet I could read the port number on the sender
side. Quite ugly but it worked.

Now comes my real recommendation: I switched to something different. I
define myself a range of UDP port numbers and try (in a loop) to open
a UDP port in that given range. The first successfully opened port
wins and I know the port number. And by having a defined port range
this makes it easier if you are behind a router where you also have to
know which ports you have to forward, plus for UDP “connections” you
have to do port forwarding both on server and client side.

Regards, ChristophAm Donnerstag, 13. April 2006 08:53 schrieb norco at ten-arc.net:

If I setup a listening port with…
udpSocket = SDLNet_UDP_Open(0);

How can I find what port was actually opened?
I have tried…
tempIPAddress = SDLNet_UDP_GetPeerAddress(udpSocket, -1);
But as reported in docs it only returns info on the port that was
specified with SDLNet_UDP_Open(port);

Im really just after the port number. Any ideas would be greatly
appreciated.
I know gethostname will get the IP, but this is not a part of
SDL_net :frowning:


_ http://wormsofprey.org
__ __ __ __ __ __ | __ __ ___
((( () | ’ | ) ) ) () | |) | ’ (/_ (|
The new and free real-time Worms game | |

If I setup a listening port with…
udpSocket = SDLNet_UDP_Open(0);

How can I find what port was actually opened?

Using port 0 (zero) is just for creating a socket to send from, not for
creating a recieving socket. If you want to create a socket to recieve
from then use something like:

udpSocket = SDLNet_UDP_Open(0xCA11);

Then you are listening on socket 0xCA11 and anyone can send to you on
that socket. There is nothing mysterious going on here. If you want to
create a listening socket at a specific port you have to provide the
port number.

Bob PendletonOn Thu, 2006-04-13 at 01:53 -0500, norco at ten-arc.net wrote:

I have tried…
tempIPAddress = SDLNet_UDP_GetPeerAddress(udpSocket, -1);
But as reported in docs it only returns info on the port that was specified
with SDLNet_UDP_Open(port);

Im really just after the port number. Any ideas would be greatly
appreciated.
I know gethostname will get the IP, but this is not a part of SDL_net :frowning:

Regards,

Si.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-------------------------------------+