<div dir="ltr">Thanks Lee!<div><br></div><div>That sheds some light on this check. I've applied this patch in order to allow loopback connects:</div><div><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo">
--- enet-1.3.9/protocol.c       2013-08-18 17:16:04.000000000 +0300</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">+++ enet-1.3.9.mod/protocol.c   2013-11-12 12:21:18.000000000 +0200</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">@@ -299,7 +299,10 @@</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">         else </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">         if (currentPeer -> address.host == host -> receivedAddress.host)</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">         {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">-            if (currentPeer -> address.port == host -> receivedAddress.port &&</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">+            /* This check prevents duplicate *connection attempts* resulting</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">+               from a connection packet being retransmitted */</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">+            if (currentPeer -> state != ENET_PEER_STATE_CONNECTING &&</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">+                currentPeer -> address.port == host -> receivedAddress.port &&</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                 currentPeer -> connectID == command -> connect.connectID)</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">               return NULL;</p></div><div><br></div><div><br></div><div><br></div><div>Is this the (<span style="font-family:Menlo;font-size:11px">ENET_PEER_STATE_CONNECTING</span>) check  you mentioned?</div>
<div><br></div><div>As for the throttling, based on my shallow view of the current implementation, I thought it won't be messed, because the throttling-related bookkeeping is *per peer*, so it won't matter where the peer comes from (localhost, another host, or the loopback connect). Am I right?</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 11:27 AM, Lee Salzman <span dir="ltr"><<a href="mailto:lsalzman@gmail.com" target="_blank">lsalzman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sorry for the late response, as I was away for the weekend. After looking into it, that check ultimately prevents duplicate *connection attempts* resulting from a connection packet being retransmitted. There is a quite easy work-around for it in theory, by just adding a check for the ENET_PEER_STATE_CONNECTING state (which indicates the sender of the connect attempt) and skipping it if it is found. What I don't know is if or how this will mess up the peer management for things like throttling when there are two peers on a single host representing both ends of a single connection, if said loopback connections where host and client are the same are allowed to proceed.<div>

<br></div><div>An enterprising person would have to experiment and verify everything works fine, but I myself won't have time to futz with this till the weekend at best.  </div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote"><div class="im">
On Fri, Nov 8, 2013 at 9:45 PM, Erwin Coumans <span dir="ltr"><<a href="mailto:erwin.coumans@gmail.com" target="_blank">erwin.coumans@gmail.com</a>></span> wrote:<br></div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><div><br></div><div>I suppose Krasimir wants to use a single ENetHosts </div><div>for server and client for this reason:</div><div><br></div><div>"If I switch to two separate ENetHosts then I can connect to myself</div>


<div>fine, but I suspect that this is going to subtly upset the</div><div>auto-throttling (i.e. each ENetHost will try to throttle around</div><div>spikes caused by the other, since they don't share accounting)."</div>


<div><br></div><div>See <a href="http://lists.cubik.org/pipermail/enet-discuss/2004-December/000313.html" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/2004-December/000313.html</a></div></div><div><br></div>

</div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On 8 November 2013 10:00, Ruud van Gaal <span dir="ltr"><<a href="mailto:ruud@racer.nl" target="_blank">ruud@racer.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr">Ah ok, but the concept behind Client & Server is that you have 2 hosts, right? A client host and a server host...<span><font color="#888888"><div>Ruud</div></font></span></div><div>
<div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 6:10 PM, Krasimir Marinov <span dir="ltr"><<a href="mailto:krasi@jklsemi.com" target="_blank">krasi@jklsemi.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You won't hit this case unless you use *only one* ENetHost. If your client and server are separate ENetHost(s) then there is no "loopback" connect. </div>



<div><div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Nov 8, 2013 at 7:02 PM, Ruud van Gaal <span dir="ltr"><<a href="mailto:ruud@racer.nl" target="_blank">ruud@racer.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">That is strange, the check and refusal of that connection.<div>One thing that might be different from my case is that I obtain the IP address of the localhost. So I setup a server at 192.168.0.10 for example, rather than 127.0.0.1.</div>





<div>The connecting client then may or may not connect to 127.0.0.1 or 192.168.0.10.</div><div>It might be interesting to see what the 4 variants do: 192.168.0.10 connecting to 127.0.0.1 and its four variants (192/192, 192/127, 127/127, 127/192).</div>





<div><br></div><div>Hm,</div><div>Ruud</div><div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 5:16 PM, Krasimir Marinov <span dir="ltr"><<a href="mailto:krasi@jklsemi.com" target="_blank">krasi@jklsemi.com</a>></span> wrote:<br>





<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I decided to dig a bit deeper into this "issue" and here are my findings:<div><br></div><div>




There is a special section in protocol.c/enet_protocol_handle_connect()/row 302 that prevents from connecting to our own host (loopback connect):</div>

<div><br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(206,121,36)">302 </span> <span style="color:rgb(206,121,36)">if</span> (currentPeer -> address.port == host -> receivedAddress.port && <span style="background-color:rgb(255,215,215)"> </span></p>







<p style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(206,121,36)">303 </span>     currentPeer -> connectID == command -> connect.connectID) {    <span style="background-color:rgb(255,215,215)"> </span></p>







<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,55,32)"><span style="color:rgb(206,121,36)">304 </span><span style="color:rgb(0,0,0)">         printf(</span>"enet_protocol_handle_connect(): loopback connect = return<span style="color:rgb(153,18,0);background-color:rgb(255,215,215)"> </span>NULL<span style="color:rgb(213,59,211)">\n</span>"<span style="color:rgb(0,0,0)">);</span></p>







<p style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(206,121,36)">305 </span>              <span style="color:rgb(83,48,225)">//return NULL;</span>                                                   <span style="background-color:rgb(255,215,215)"> </span></p>







<p style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(206,121,36)">306 </span> }                  </p><div>I've modified it with a printf() statement to debug.</div><div><br></div><div>With the following test program when using the original version I'm unable to connect to myself. With the modified ENet version I get two connect events - one for the peer initiating connect and one for the peer being connected.</div>






<div><br></div><div>This is the output:</div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo">Connecting peer 0x7fed91006000</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">enet_protocol_handle_connect(): loopback connect = return NULL</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">A new peer (0x7fed91006000) connected from 100007f:55555.</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">A new peer (0x7fed910061d0) connected from 100007f:55555.</p></div><div class="gmail_extra"><br>And here is the program:</div><div class="gmail_extra"><br></div><div class="gmail_extra">






<p style="margin:0px;font-size:11px;font-family:Menlo">#include <enet/enet.h></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">#include <stdio.h></p><p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">int main() {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  ENetAddress address;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  ENetHost *host;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  ENetPeer *peer;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  ENetEvent event;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  enet_address_set_host(&address, "127.0.0.1");</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  address.port = 55555;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  host = enet_host_create (&address, 32, 1, 0, 0);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  peer = enet_host_connect(host, &address, 1, 0);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  printf("Connecting peer %p\n", peer);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  while (enet_host_service (host, & event, 100000) > 0) {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    switch (event.type) {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    case ENET_EVENT_TYPE_CONNECT:</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      printf ("A new peer (%p) connected from %x:%u.\n",</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.peer,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.peer -> address.host,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.peer -> address.port);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      /* Store any relevant client information here. */</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      event.peer -> data = "Client information";</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      break;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    case ENET_EVENT_TYPE_RECEIVE:</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      printf ("A packet of length %lu containing %s was received from %s on channel %u.\n",</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.packet -> dataLength,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.packet -> data,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.peer -> data,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">              event.channelID);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      /* Clean up the packet now that we're done using it. */</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      enet_packet_destroy (event.packet);    </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      break;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">      </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    case ENET_EVENT_TYPE_DISCONNECT:</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      if(event.peer->data)</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">        printf ("%p: %s disconected.\n", event.peer, event.peer -> data);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      else</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">        printf("%p: disconnected\n", event.peer);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      /* Reset the peer's client information. */</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      event.peer -> data = NULL;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      break;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    default:</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      printf("default\n");</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">      break;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">  }</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><div class="gmail_quote">Regards,</div>






<div class="gmail_quote">Krasimir</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Thu, Nov 7, 2013 at 12:45 PM, Krasimir Marinov <span dir="ltr"><<a href="mailto:krasi@jklsemi.com" target="_blank">krasi@jklsemi.com</a>></span> wrote:<br>






<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">The code that you shared connects peers from 2 different ENetHosts.<div>






<br></div><div>The pseudocode that I showed</div><div><div><div style="font-family:arial,sans-serif;font-size:13px">    </div><div style="font-family:arial,sans-serif;font-size:13px">
    ENetAddress address;</div><div style="font-family:arial,sans-serif;font-size:13px">    a.host = <localhost></div><div style="font-family:arial,sans-serif;font-size:13px">    a.port = <port></div><div style="font-family:arial,sans-serif;font-size:13px">







<br></div><div style="font-family:arial,sans-serif;font-size:13px">    EnetHost *host = enet_host_create(&address, .....);</div><div style="font-family:arial,sans-serif;font-size:13px">    enet_host_connect(host, &address, ...);</div>







</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">tries to connect the host to itself. Notice that there is only one address and one host!</div>







<div style="font-family:arial,sans-serif;font-size:13px"> </div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Nov 7, 2013 at 12:08 PM, Andrew Fenn <span dir="ltr"><<a href="mailto:andrewfenn@gmail.com" target="_blank">andrewfenn@gmail.com</a>></span> wrote:<br>







<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I don't have any problems with a running a client / server on the same<br>







machine. My code is available here, it's unfinished overall however<br>
the enet connection stuff has worked without problems for a long time.<br>
<br>
<a href="https://github.com/andrewfenn/Hardwar" target="_blank">https://github.com/andrewfenn/Hardwar</a><br>
Server: <a href="https://github.com/andrewfenn/Hardwar/blob/master/code/server/src/Server.cpp" target="_blank">https://github.com/andrewfenn/Hardwar/blob/master/code/server/src/Server.cpp</a><br>
Client: <a href="https://github.com/andrewfenn/Hardwar/blob/master/code/client/tasks/src/NetworkTask.cpp" target="_blank">https://github.com/andrewfenn/Hardwar/blob/master/code/client/tasks/src/NetworkTask.cpp</a><br>
<div><div><br>
On Thu, Nov 7, 2013 at 5:00 PM, Ruud van Gaal <<a href="mailto:ruud@racer.nl" target="_blank">ruud@racer.nl</a>> wrote:<br>
> All I can say that in principle this works; I use this every day (a single<br>
> exe running both and a server and a client, where the client connects to its<br>
> own server).<br>
> Ruud<br>
><br>
><br>
> On Wed, Nov 6, 2013 at 2:37 PM, Krasimir Marinov <<a href="mailto:krasi@jklsemi.com" target="_blank">krasi@jklsemi.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I’ve been trying to connect to the host:port that my ENetHost is bound to,<br>
>> i.e. connect and send to myself.<br>
>> Unfortunately this almost immediately results in event DISCONNECT.<br>
>><br>
>> Looking at the archives I found the same problem raised 9 years ago (see<br>
>> below).<br>
>><br>
>> Any reason for this behaviour?<br>
>><br>
>> Regards,<br>
>> Krasimir<br>
>><br>
>> [ENet-discuss] Connecting to self.<br>
>><br>
>> Adam D. Moss adam at <a href="http://gimp.org" target="_blank">gimp.org</a><br>
>> Wed Dec 1 08:44:30 PST 2004<br>
>><br>
>> Next message: [ENet-discuss] Connecting to self.<br>
>> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]<br>
>><br>
>> ________________________________<br>
>><br>
>> Hi!<br>
>> I have a funny problem.  My app listens on a port and then attempts<br>
>> to connect to itself (for testing purposes, for now).  But this<br>
>> merely eventually causes a DISCONNECT (presumably time-out) event,<br>
>> with no CONNECT.<br>
>><br>
>> However, if I launch a second process and do the connect from<br>
>> there, the connection is fine.<br>
>><br>
>> Am I being stupid for attempting to have a process be a client<br>
>> of its own server, or is there some unexpected strangeness which<br>
>> prevents an ENet server from being its own client?<br>
>><br>
>> Thanks,<br>
>> --Adam<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>
><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>
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>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
<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></blockquote></div><br></div>
</div></div><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></blockquote></div><br></div>
</div></div><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></blockquote></div><br></div>
</div></div><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></blockquote></div><br></div>
</div></div><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></blockquote></div></div></div><br></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>