<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Marc Rochel wrote:
<blockquote
cite="mid:E9BC41701AC6E74E906356F37D60B98E4564F9@owa.udicom.de"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="Section1">
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Hi
!<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
lang="EN-US">Something related was bugging me some time as well. When
you try
to connect, after a while, if successful, you get a </span><span
style="font-size: 10pt; font-family: "Courier New"; color: windowtext;"
lang="EN-US">ENET_EVENT_TYPE_CONNECT,
but you never get a notification when the connection doesn’t get
established.
Maybe enet keeps trying infinitly itself? I “solved” the issue for me
by
checking if some selfdefined timeout is passed and the call
enet_host_destroy. Creating
a new one afterwards and trying to connect again works.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Courier New"; color: windowtext;"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Courier New"; color: windowtext;"
lang="EN-US">Best regards<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Courier New"; color: windowtext;"
lang="EN-US"> Marc<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
lang="EN-US"><o:p> </o:p></span></p>
<div>
<div
style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;">
<p class="MsoNormal"><b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US">From:</span></b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US">
<a class="moz-txt-link-abbreviated" href="mailto:enet-discuss-bounces@cubik.org">enet-discuss-bounces@cubik.org</a> [<a class="moz-txt-link-freetext" href="mailto:enet-discuss-bounces@cubik.org">mailto:enet-discuss-bounces@cubik.org</a>] <b>On
Behalf Of </b>William Brandt<br>
<b>Sent:</b> Donnerstag, 18. Juni 2009 19:08<br>
<b>To:</b> Discussion of the ENet library<br>
<b>Subject:</b> Re: [ENet-discuss] ENetPeer structure when
reconnecting<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ruud van Gaal wrote: <o:p></o:p></p>
<pre>This all sounds familiar. I have this connection scheme with the following<o:p></o:p></pre>
<pre>properties:<o:p></o:p></pre>
<pre>- the server may not be online yet<o:p></o:p></pre>
<pre>- the client attempts a connection every second or 2, to see if the server<o:p></o:p></pre>
<pre>is already alive<o:p></o:p></pre>
<pre>- I only want 1 connection (client<->server)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>I have a C++ wrapper (class QNClient) which only tracks 1 peer. This client<o:p></o:p></pre>
<pre>class is legacy and only represents 1 link to a server (class QNServer).<o:p></o:p></pre>
<pre>For repeated connection attempts, this was no problem in the past (without<o:p></o:p></pre>
<pre>ENet); I sent out some kind of CONNECT packet, and if something came back,<o:p></o:p></pre>
<pre>it was connected.<o:p></o:p></pre>
<pre>With the ENet peer, I start an enet_host_connect() with every connection<o:p></o:p></pre>
<pre>attempt. If I create an ENet host with only 1 peer, I run out of peers after<o:p></o:p></pre>
<pre>this first connect attempt.<o:p></o:p></pre>
<pre>It's a bit awkward, since if I allow more peers in the ENet host, multiple<o:p></o:p></pre>
<pre>peers may connect succesfully. I'll have to drop the surplus of connections<o:p></o:p></pre>
<pre>once the server comes up and it turns out I get multiple<o:p></o:p></pre>
<pre>ENET_EVENT_TYPE_CONNECT events.<o:p></o:p></pre>
<pre>It seems to work though with 1 peer, I just get a lot of 'out of peer' error<o:p></o:p></pre>
<pre>when trying enet_host_connect(). I haven't tried resetting the peer; I don't<o:p></o:p></pre>
<pre>think I want to since a connect reply may still be incoming and I'd rather<o:p></o:p></pre>
<pre>handle that as usual.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Ruud<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><o:p> </o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>-----Oorspronkelijk bericht-----<o:p></o:p></pre>
<pre>Van: <a moz-do-not-send="true"
href="mailto:enet-discuss-bounces@cubik.org">enet-discuss-bounces@cubik.org</a> <o:p></o:p></pre>
<pre>[<a moz-do-not-send="true"
href="mailto:enet-discuss-bounces@cubik.org">mailto:enet-discuss-bounces@cubik.org</a>] Namens Daniel Aquino<o:p></o:p></pre>
<pre>Verzonden: Thursday, June 18, 2009 18:13<o:p></o:p></pre>
<pre>Aan: Discussion of the ENet library<o:p></o:p></pre>
<pre>Onderwerp: Re: [ENet-discuss] ENetPeer structure when reconnecting<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Perhaps as I said you ran out of peers... So until the <o:p></o:p></pre>
<pre>callback stack was finished that peer wouldn't be free yet...<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>On Wed, Jun 17, 2009 at 11:23 PM, William <o:p></o:p></pre>
<pre>Brandt<a moz-do-not-send="true"
href="mailto:taekvideo@gmail.com"><taekvideo@gmail.com></a> wrote:<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>Daniel Aquino wrote:<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>>From what i know there is no deleting. I believe enet <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>will clean up<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>the peer after it has told you about the event and you have had a <o:p></o:p></pre>
<pre>chance to react. And the connection function will return a <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>new peer <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>with no way to re-use the existing peer that I know of... <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>Which does <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>confuse me a bit in the case of attempting to make a new connection <o:p></o:p></pre>
<pre>inside of the disconnection event when there is no more <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>peers left...<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>I don't know if in that case it would still consider that peer as <o:p></o:p></pre>
<pre>valid resulting in the inability to form a new connection or if it <o:p></o:p></pre>
<pre>would end up using that same peer destroying data inside of it that <o:p></o:p></pre>
<pre>you may still need... So I copied any data I needed from the peer<o:p></o:p></pre>
<pre>object before making the new connection just in case... I guess<o:p></o:p></pre>
<pre>these questions could be solved easily by looking into the <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>enet code <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>or setting the peer count to 1 and doing some testing...<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>On Wed, Jun 17, 2009 at 2:47 PM, William <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>Brandt<a moz-do-not-send="true"
href="mailto:taekvideo@gmail.com"><taekvideo@gmail.com></a> wrote:<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre><o:p> </o:p></pre>
<pre>When a user is disconnected from the server and is <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>reconnecting, do I <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>need to get a new ENetPeer object (from the enet_host_connect() <o:p></o:p></pre>
<pre>function), or is it possible to use the same one to <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>reconnect? Also, <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>if I have to get a new one, do I need to delete the old one (& how)?<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
</blockquote>
<pre>...<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>well what I'm doing now seems to be working...<o:p></o:p></pre>
<pre>the main problem I was having was that enet_host_connect() was <o:p></o:p></pre>
<pre>returning NULL when I tried to reconnect. It seems I had to <o:p></o:p></pre>
<pre>explicitly call<o:p></o:p></pre>
<pre>enet_peer_reset() on the old peer object before I reconnect <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
<pre>and get a <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;">
<pre>new peer object.<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</blockquote>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>ENet-discuss mailing list<o:p></o:p></pre>
<pre><a moz-do-not-send="true" href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><o:p></o:p></pre>
<pre><a moz-do-not-send="true"
href="http://lists.cubik.org/mailman/listinfo/enet-discuss">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> <o:p></o:p></pre>
<p class="MsoNormal">You should add a 5000ms delay when you call
enet_host_service() to check for connect events after calling
enet_host_connect(). Then if you don't get a response you can safely
assume that the server isn't going to respond and reset the peer then
try
again.<o:p></o:p></p>
</div>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
ENet-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a>
<a class="moz-txt-link-freetext" href="http://lists.cubik.org/mailman/listinfo/enet-discuss">http://lists.cubik.org/mailman/listinfo/enet-discuss</a>
</pre>
</blockquote>
you can do that in one line. It's safe to assume that you won't get
any events other than a connection confirmation if you're not
connected... so you can use the enet_host_service() built-in timeout
feature. This is what I use (in a connect() function that returns true
when connection succeeded or false when it failed):<br>
<br>
peer_ = enet_host_connect (client_, &address, 2); <br>
if (peer_ == NULL) throw "ERROR: Unable to initiate Enet peer
connection.";<br>
if (enet_host_service (client_, &event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT) return true;<br>
else{<br>
enet_peer_reset (peer_);<br>
return false;<br>
}<br>
</body>
</html>