<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6396.0">
<TITLE>ENET Client getting backed up with Reliable Packets</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">Thought that I</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">’</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">d post this around and see if anyone has any ideas</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">. Simple Console App. BTW I have also a file to allow ethereal to decode</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">the</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ENET Protocol if anyone is interested</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">:</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">I believe that I</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">’</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">m just not setting up my test server and client properly to handle the command flow. What I have is a client that tries to send 10</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">24 reliable packets of 100</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">bytes of data</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">each</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">as fast as he can</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">. He ends up able to send 327 reliable packets. Then since we have not received an ACK back from the server he queues the remainin</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">g packets.</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> If I slow this down by either setting the enet_host_server timeout value to ~</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">1</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">00ms or</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">inserting a Sleep(100) in my loop then the server has time to send the ACK and so the entire 1024 packets are sent.</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">I believe what I need is somewhy to detect that there are packets still to be</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">transferred</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> out and not exit out of my program. Does anyone have any ideas about this?</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">Jeff</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"></SPAN><A NAME=""><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Jeffrey B. Holtz</FONT></SPAN></A></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Senior Software Engineer</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Accurate Technologies Inc.</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">47199 Cartier Dr, Wixom, MI 48393</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ph: 248-848-9200</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">fax: 248-848-9016</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">jholtz@accuratetechnologies.com</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us">// Server.c</SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#include</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> "stdafx.h"</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#include</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> "enet/enet.h"</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#define</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> MAX_CLIENT_NAME 100</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">char</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ClientName[MAX_CLIENT_NAME];</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">const</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ServerPort=1234;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> _tmain(</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> argc, _TCHAR* argv[])</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Setup Console App to contain a large buffer for debug purposes */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">HANDLE hStdout; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">CONSOLE_SCREEN_BUFFER_INFO csbiInfo; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">COORD dwSize;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">hStdout = GetStdHandle(STD_OUTPUT_HANDLE); </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Get the current screen buffer size and window position. </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 1; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">dwSize.X=120;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">dwSize.Y=1024*4;</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#008000" SIZE=2 FACE="Courier New">// 4 K</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (! SetConsoleScreenBufferSize(hStdout,dwSize))</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 1; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (enet_initialize() != 0)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">fprintf (stderr, "An error occurred while initializing ENet.\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> EXIT_FAILURE;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">atexit (enet_deinitialize);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Create Server</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetAddress address;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetHost * server;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetEvent event;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Bind the server to the default localhost. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* A specific host address can be specified by */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* enet_address_set_host (& address, "x.x.x.x"); */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> address.host = ENET_HOST_ANY;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Bind the server to port 1234. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">address.port = ServerPort;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">server = enet_host_create (& address</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* the address to bind the server host to */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">, </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 32 </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* allow up to 32 clients and/or outgoing connections */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 0 </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* assume any amount of incoming bandwidth */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 0 </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* assume any amount of outgoing bandwidth */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (server == NULL)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> fprintf (stderr, </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> "An error occurred while trying to create an ENet server host.\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> exit (EXIT_FAILURE);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">for</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (;;)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (enet_host_service (server, & event,1000) < 0)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">break</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">switch</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (event.type)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">case</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ENET_EVENT_TYPE_CONNECT:</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetAddress enetAddress;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">char</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> * ClientData = (</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">char</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> *)malloc(MAX_CLIENT_NAME);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">memset(ClientData,0x00,MAX_CLIENT_NAME);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">memset(ClientName,0x00,MAX_CLIENT_NAME);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enetAddress.host = event.peer->address.host;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enetAddress.port = event.peer->address.port;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (!enet_address_get_host(&enetAddress,ClientName,MAX_CLIENT_NAME))</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New"> sprintf (ClientData, "%s:%u", ClientName, event.peer->address.port);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">else</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New"> sprintf (ClientData, "%x:%u\n", event.peer->address.host, event.peer->address.port);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf ("A new client connected from %s.\n", ClientData);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Store any relevant client information here. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">event.peer -> data = ClientData;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">break</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">case</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ENET_EVENT_TYPE_RECEIVE:</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf ("Received: %d bytes in %u ms from peer ID %u\n",</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">event.packet -> dataLength,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">event.peer -> roundTripTime,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">event.peer -> incomingPeerID);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Clean up the packet now that we're done using it. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_packet_destroy (event.packet);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">break</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">case</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ENET_EVENT_TYPE_DISCONNECT:</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Reset the peer's client information. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (event.peer->data != NULL)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf ("Peer <%s> disconnected \n", event.peer->data);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">free(event.peer->data);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">event.peer -> data = NULL;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">else</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf ("Unknown Peer disconnected\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Cleanup Server</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_host_destroy(server);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 0;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<BR>
<P ALIGN=LEFT><SPAN LANG="en-us">// Client.c</SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#include</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> "stdafx.h"</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#include</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> "enet/enet.h"</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">#define</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> SEND_BUFFER_SIZE 100</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">const</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">char</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> *ServerIP="10.1.60.7";</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">const</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ServerPort=1234;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> _tmain(</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> argc, _TCHAR* argv[])</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Setup Console App to contain a large buffer for debug purposes */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">HANDLE hStdout; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">CONSOLE_SCREEN_BUFFER_INFO csbiInfo; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">COORD dwSize;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">hStdout = GetStdHandle(STD_OUTPUT_HANDLE); </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Get the current screen buffer size and window position. </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 1; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">dwSize.X=120;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">dwSize.Y=1024*4;</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#008000" SIZE=2 FACE="Courier New">// 4 Kb</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (! SetConsoleScreenBufferSize(hStdout,dwSize))</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> </FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 1; </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Initialize Enet</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (enet_initialize () != 0)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">fprintf (stderr, "An error occurred while initializing ENet.\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> EXIT_FAILURE;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">atexit (enet_deinitialize);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Create Client</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetPeer *peer;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetHost * client;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetAddress address;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetEvent event;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">client = enet_host_create (NULL</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* create a client host */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">1</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* only allow 1 outgoing connection */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">0</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Allow Maximum downstream bandwidth */</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">,</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">0);</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Allow Maximum upstream bandwidth */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (client == NULL)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">fprintf (stderr, "An error occurred while trying to create an ENet client host.\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">exit (EXIT_FAILURE);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Connect to ServerIP:ServerPort. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_address_set_host (& address, ServerIP);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">address.port = ServerPort;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Initiate the connection, allocating the two channels 0 and 1. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">peer = enet_host_connect (client, & address, 2); </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (peer == NULL)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">fprintf (stderr,</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">"No available peers for initiating an ENet connection.\n");</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">exit (EXIT_FAILURE);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Wait up to 5 seconds for the connection attempt to succeed.*/</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> ((enet_host_service (client, & event, 5000) > 0) && </FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">(event.type==ENET_EVENT_TYPE_CONNECT))</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">char</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> pData[SEND_BUFFER_SIZE];</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">memset(pData,0x00,SEND_BUFFER_SIZE);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf ("Connection to %s:%d succeeded.\n",ServerIP,ServerPort);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">for</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">int</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> nPacketNumber=0; nPacketNumber<1024; nPacketNumber++)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">sprintf(pData,"%0</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">4</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">d",nPacketNumber);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Create a reliable packet of size SEND_BUFFER_SIZE containing "packet\0" */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">ENetPacket * pPacket = enet_packet_create (pData, SEND_BUFFER_SIZE, ENET_PACKET_FLAG_RELIABLE);</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Send the packet to the peer over channel id 0. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* One could also broadcast the packet by */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* enet_host_broadcast (host, 3, packet); */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_peer_send (peer, 0, pPacket);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Execute Send/Receive Service</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (enet_host_service (client, & event, 0) < 0)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">break</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">else</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">{</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">printf("Connection to %s:%d failed.", ServerIP, ServerPort);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* Either the 5 seconds are up or a disconnect event was */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* received. Reset the peer in the event the 5 seconds */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">/* had run out without any significant event. */</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">if</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> (event.type != ENET_EVENT_TYPE_DISCONNECT)</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_peer_reset (peer);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">}</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">// Cleanup Client</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> <FONT SIZE=2 FACE="Courier New">enet_host_destroy(client);</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"> </SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT COLOR="#0000FF" SIZE=2 FACE="Courier New">return</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> 0;</FONT></SPAN></P>
<P ALIGN=LEFT><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">}</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
</BODY>
</HTML>