[ENet-discuss] Is the client port always random?

Sebastian Ahlman sebastian.ahlman at gmail.com
Mon Oct 17 11:09:33 PDT 2011


Hi!

This might seem like a stupid question, so I apologize in advance if I have
misunderstood something. I have used ENet for quite some time now, not
paying that much attention to what ports I am using, and everything has
worked fine. I am currently investigating how to incorporate NAT punch
through using ENet, and one thing came to mind:

Say I have a server and a client. The server creates a host
using enet_host_create() and passes in the following address:

ENetAddress address;
address.host = ENET_HOST_ANY;
address.port = 1234;

Okay, so now I can create a client on the other end and connect to the
server using its IP address and port 1234. When the server receives the
data, it prints it to the console along with the IP and port of the sender.
Up until this point I have always assumed that the port of the client would
also be 1234, but this does not seem to be that case. The port changes every
time I connect to the server.

This might not be something that prevents me from doing NAT punch through
(though it just as well might, I have not yet done it), but I would like to
understand how the system chooses the port for the client, and if there is a
way to specify the port to be used. Also, is there any reason I would want
to specify the port, or is it better to allow the system to choose it for
me?

Thank you!

//Sebastian Ahlman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20111017/e0f3131d/attachment.html>


More information about the ENet-discuss mailing list