<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 class="im"><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 class=""><div class="h5"><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>