Yes, as the app developer, *you* pick a port and start connecting to the server, which is listening to that port. You're in control of the port number directly.<div><br></div><div>Do note that writing to the same host in multiple processes or threads does require you to put a semaphore (or similar) to avoid accessing the same 'host' pointer by multiple threads. That is NOT handled by ENet itself (basically consider it a re-entrant unsafe library).</div>
<div><br></div><div>Ruud<br><br><div class="gmail_quote">On Thu, Jul 12, 2012 at 2:57 PM, Soren Dreijer <span dir="ltr"><<a href="mailto:dreijer@echobit.com" target="_blank">dreijer@echobit.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I don’t follow. Enet is only using a single port and multiplexes all connections through that single port. That is, it doesn’t matter whether you’re communicating with one or ten remote hosts; all traffic will go through that one port that Enet is bound to. <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">*<b>You</b>* are in charge of choosing the port when you set up Enet (i.e. call enet_host_create), so I’m a little confused what the problem is. If you create 20 Enet instances in 20 different processes, then they’d all have different ports that you’ve chosen and thus know.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Maybe if you described what you’re really trying to achieve, I can better understand. :)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">/ Soren <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:enet-discuss-bounces@cubik.org" target="_blank">enet-discuss-bounces@cubik.org</a> [mailto:<a href="mailto:enet-discuss-bounces@cubik.org" target="_blank">enet-discuss-bounces@cubik.org</a>] <b>On Behalf Of </b>Siqi Shen<br>
<b>Sent:</b> Thursday, July 12, 2012 4:24 AM<br><b>To:</b> <a href="mailto:enet-discuss@cubik.org" target="_blank">enet-discuss@cubik.org</a><br><b>Subject:</b> Re: [ENet-discuss] How can I get the client port created in my client side (Soren Dreijer)<u></u><u></u></span></p>
</div></div><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks for your reply. Setting port in enet_host_create is not flexible enough, as I may create more than 20 processes/threads.  I think that once a udp diagram has been setup ( sendto() function has been called), the udp port  in the client side is determine and it will be consistent across the whole application if we don't change the port manually. <u></u><u></u></p>
<div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">As I am using Win7 64bit. I use "netstat -an -p udp -o" to get the udp port and process id mapping and find that the UDP port I created in my process through enet is consistent. And as described in MSDN <u></u><u></u></p>
</div><div><p class="MsoNormal">"<a href="http://msdn.microsoft.com/en-us/library/ms740148%28VS.85%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms740148%28VS.85%29.aspx</a>" that "<span style="font-size:10.0pt;font-family:"Segoe UI","sans-serif"">If a socket is opened, a </span><a href="http://msdn.microsoft.com/en-us/library/ms740476(v=vs.85).aspx" target="_blank"><strong><span style="font-size:10.0pt;font-family:"Segoe UI","sans-serif";color:#960bb4;text-decoration:none">setsockopt</span></strong></a><span style="font-size:10.0pt;font-family:"Segoe UI","sans-serif""> call is made, and then a <strong><span style="font-family:"Segoe UI","sans-serif"">sendto</span></strong> call is made, Windows Sockets performs an implicit <strong><span style="font-family:"Segoe UI","sans-serif"">bind</span></strong> function call.</span>"<u></u><u></u></p>
</div><div><p class="MsoNormal">so we can get the port through "<a href="http://msdn.microsoft.com/en-us/library/ms738543(v=vs.85).aspx" target="_blank"><strong><span style="font-size:10.0pt;font-family:"Segoe UI","sans-serif";color:#960bb4;text-decoration:none">getsockname</span></strong></a><span style="font-size:10.0pt;font-family:"Segoe UI","sans-serif""> </span>" function.  But I can not get the port in enet (I want to use the port number for debugging).  Do you have a better solution besides setting port manually?<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">2012/7/11 <<a href="mailto:enet-discuss-request@cubik.org" target="_blank">enet-discuss-request@cubik.org</a>><u></u><u></u></p>
<p class="MsoNormal">Send ENet-discuss mailing list submissions to<br>        <a href="mailto:enet-discuss@cubik.org" target="_blank">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" target="_blank">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" target="_blank">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.  How can I get the client port created in my client       side<br>      (Siqi Shen)<br>   2. Re:  How can I get the client port created in my  client  side<br>
      (Soren Dreijer)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Wed, 11 Jul 2012 13:48:44 +0200<br>From: Siqi Shen <<a href="mailto:siqishen@gmail.com" target="_blank">siqishen@gmail.com</a>><br>
To: <a href="mailto:enet-discuss@cubik.org" target="_blank">enet-discuss@cubik.org</a><br>Subject: [ENet-discuss] How can I get the client port created in my<br>        client  side<br>Message-ID:<br>        <<a href="mailto:CAD6PKm0KJqwY-Rf5rSeBOL3ru7x7c2jEyxYvRCAExD1QrecMrQ@mail.gmail.com" target="_blank">CAD6PKm0KJqwY-Rf5rSeBOL3ru7x7c2jEyxYvRCAExD1QrecMrQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br><br>Hi All,<br><br>I am developing a small game using enet as network layer. My question is<br>that how can I know the port I created in my client side to connect to<br>
remote host. I know that I can know the client's port in server's side when<br>ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use<br>enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT receive in<br>
client's side. Anyone know how to deal with this problem?<br><br>Thanks and best regards,<br>Siqi<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <<a href="http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/c64afa88/attachment-0001.html" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/c64afa88/attachment-0001.html</a>><br>
<br>------------------------------<br><br>Message: 2<br>Date: Wed, 11 Jul 2012 08:04:40 -0500<br>From: "Soren Dreijer" <<a href="mailto:dreijer@echobit.net" target="_blank">dreijer@echobit.net</a>><br>To: "'Discussion of the ENet library'" <<a href="mailto:enet-discuss@cubik.org" target="_blank">enet-discuss@cubik.org</a>><br>
Subject: Re: [ENet-discuss] How can I get the client port created in<br>        my      client  side<br>Message-ID: <011301cd5f65$bc210a70$34631f50$@<a href="http://echobit.net" target="_blank">echobit.net</a>><br>Content-Type: text/plain; charset="us-ascii"<br>
<br>You're using UDP and you therefore don't have separate client-side ports<br>when you "connect" to a server.<br><br><br><br>The port you're using on the client is the one you specified in<br>enet_host_create() when you initialized enet.<br>
<br><br><br>From: <a href="mailto:enet-discuss-bounces@cubik.org" target="_blank">enet-discuss-bounces@cubik.org</a> [mailto:<a href="mailto:enet-discuss-bounces@cubik.org" target="_blank">enet-discuss-bounces@cubik.org</a>]<br>
On Behalf Of Siqi Shen<br>Sent: Wednesday, July 11, 2012 6:49 AM<br>To: <a href="mailto:enet-discuss@cubik.org" target="_blank">enet-discuss@cubik.org</a><br>Subject: [ENet-discuss] How can I get the client port created in my client<br>
side<br><br><br><br>Hi All,<br><br><br><br>I am developing a small game using enet as network layer. My question is<br>that how can I know the port I created in my client side to connect to<br>remote host. I know that I can know the client's port in server's side when<br>
ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use<br>enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT receive in<br>client's side. Anyone know how to deal with this problem?<br><br>
<br><br>Thanks and best regards,<br><br>Siqi<br><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <<a href="http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/8830cb5d/attachment-0001.html" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/8830cb5d/attachment-0001.html</a>><br>
<br>------------------------------<br><br>_______________________________________________<br>ENet-discuss mailing list<br><a href="mailto:ENet-discuss@cubik.org" target="_blank">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 109, Issue 1<br>********************************************<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div><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></blockquote></div><br></div>