Thanks for clearing this up for me. The tutorial on ENet's site claims that "<span class="Apple-style-span" style="font-family: 'Lucida Grande', Verdana, Geneva, Arial, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255); ">Clients in ENet are similarly constructed with <a class="el" href="http://enet.bespin.org/group__host.html#ga5567a95d7a45521dc9cba93a9066c940" title="Creates a host for communicating to peers." style="color: rgb(61, 87, 140); font-weight: bold; text-decoration: none; ">enet_host_create()</a> when no address is specified to bind the host to.", which is why I have always created my game clients with NULL passed as the first parameter to enet_host_create().</span><div>
<div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;">Does this mean that technically a third party could connect to the peer to be used as a client, provided that:</span></font></div>
<div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;">1. the third party gets the address and port number correct and</span></font></div>
<div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;">2. the client has not yet connected to the peer it considers the "server"?</span></font></div>
<div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px;">Also, does the host field of the address struct have any meaning on a client peer, ie. a peer that does not "listen" for connections, but only connects to other peers? Should I use </span></font>ENET_HOST_ANY on the clients as well, if I want to be able to connect to "any server"?</div>
<div><br></div><div>Thanks again!</div><div><br></div><div>//Sebastian</div><div><br><div class="gmail_quote">On Mon, Oct 17, 2011 at 10:00 PM,  <span dir="ltr"><<a href="mailto:enet-discuss-request@cubik.org">enet-discuss-request@cubik.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Send ENet-discuss mailing list submissions to<br>
        <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:enet-discuss-request@cubik.org">enet-discuss-request@cubik.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:enet-discuss-owner@cubik.org">enet-discuss-owner@cubik.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of ENet-discuss digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1.  Is the client port always random? (Sebastian Ahlman)<br>
   2. Re:  Is the client port always random? (Lee Salzman)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 17 Oct 2011 21:09:33 +0300<br>
From: Sebastian Ahlman <<a href="mailto:sebastian.ahlman@gmail.com">sebastian.ahlman@gmail.com</a>><br>
To: <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a><br>
Subject: [ENet-discuss] Is the client port always random?<br>
Message-ID:<br>
        <CAOzyQYFbU2jSXmB5Zj1Srecw4iFsc7GSVwiz96k+nf9qc4MS=<a href="mailto:w@mail.gmail.com">w@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hi!<br>
<br>
This might seem like a stupid question, so I apologize in advance if I have<br>
misunderstood something. I have used ENet for quite some time now, not<br>
paying that much attention to what ports I am using, and everything has<br>
worked fine. I am currently investigating how to incorporate NAT punch<br>
through using ENet, and one thing came to mind:<br>
<br>
Say I have a server and a client. The server creates a host<br>
using enet_host_create() and passes in the following address:<br>
<br>
ENetAddress address;<br>
address.host = ENET_HOST_ANY;<br>
address.port = 1234;<br>
<br>
Okay, so now I can create a client on the other end and connect to the<br>
server using its IP address and port 1234. When the server receives the<br>
data, it prints it to the console along with the IP and port of the sender.<br>
Up until this point I have always assumed that the port of the client would<br>
also be 1234, but this does not seem to be that case. The port changes every<br>
time I connect to the server.<br>
<br>
This might not be something that prevents me from doing NAT punch through<br>
(though it just as well might, I have not yet done it), but I would like to<br>
understand how the system chooses the port for the client, and if there is a<br>
way to specify the port to be used. Also, is there any reason I would want<br>
to specify the port, or is it better to allow the system to choose it for<br>
me?<br>
<br>
Thank you!<br>
<br>
//Sebastian Ahlman<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.cubik.org/pipermail/enet-discuss/attachments/20111017/e0f3131d/attachment-0001.html" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/attachments/20111017/e0f3131d/attachment-0001.html</a>><br>

<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 17 Oct 2011 14:58:54 +0300<br>
From: Lee Salzman <<a href="mailto:lsalzman@gmail.com">lsalzman@gmail.com</a>><br>
To: Discussion of the ENet library <<a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>><br>
Subject: Re: [ENet-discuss] Is the client port always random?<br>
Message-ID: <<a href="mailto:4E9C187E.7060406@gmail.com">4E9C187E.7060406@gmail.com</a>><br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
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.<br>

<br>
On 10/17/2011 09:09 PM, Sebastian Ahlman wrote:<br>
> Hi!<br>
><br>
> 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:<br>

><br>
> Say I have a server and a client. The server creates a host using enet_host_create() and passes in the following address:<br>
><br>
> ENetAddress address;<br>
> address.host = ENET_HOST_ANY;<br>
> address.port = 1234;<br>
><br>
> 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.<br>

><br>
> 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?<br>

><br>
> Thank you!<br>
><br>
> //Sebastian Ahlman<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br>
<br>
End of ENet-discuss Digest, Vol 101, Issue 2<br>
********************************************<br>
</blockquote></div><br></div></div>