[ENet-discuss] Is the client port always random?
Lee Salzman
lsalzman at gmail.com
Mon Oct 17 04:58:54 PDT 2011
The port is whatever the operating system chooses IF you do not specify a port. So just specify a port, like you did in the code below. There's really no such thing as an ENet server or client, as all providing an address to enet_host_create() does is give a preference instead of letting the OS choose. What you consider a server or client is a matter of interpretation, not of code policy in ENet.
On 10/17/2011 09:09 PM, Sebastian Ahlman wrote:
> 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
More information about the ENet-discuss
mailing list