<div>Wow, thanks for the fast reply.</div>
<div>&nbsp;</div>
<div>You cleared up quite a bit of my confusion, too.</div>
<div>&nbsp;</div>
<div>I ditched my vector of peer pointers, and am now using the host-&gt;peers instead.</div>
<div>Also, instead of using a dummy connection when I want to play on&nbsp;non-dedicated server, I do something like this:</div>
<div>&nbsp;</div>
<div>maxPlayers = 12;</div>
<div>if(!dedicated) maxPlayers--;</div>
<div>host = enet_host_create(&amp;address, maxPlayers, 0, 0);</div>
<div>serverPlayer = maxPlayers;</div>
<div>&nbsp;</div>
<div>this will only allow for 11 other players to join. And they will fill spots 0 to 10 in the host-&gt;peers array.</div>
<div>The player&nbsp;the server&nbsp;now controls is player[serverPlayer] - which is the 12th and final player. So I don&#39;t have to worry about it being replaced, etc..</div>
<div>&nbsp;</div>
<div>Hooray, first 4 questions solved!</div>
<div>&nbsp;</div>
<div>As far as question 5 goes, I&#39;m now using ENET_HOST_ANY. Regarding LAN.. what should I do then? Keep it as ENET_HOST_ANY? I read somewhere that the client should then set it&#39;s address to ENET_HOST_BROADCAST, and that will return any server addresses? I tried, but it didn&#39;t work.. Do I have to connect twice or something? Once to find the address, and then again to connect to it?</div>

<div>&nbsp;</div>
<div>Also, can a server host for both LAN and the internet at the same time? So anyone can join, whether they&#39;re in the LAN or on the net? If not, for testing purposes, is it possible for me to use my second computer which is on the LAN, but get it to join via the internet, so I can check to see if I&#39;ve got both the LAN connection and the internet connections working properly. I&#39;ve been reading a lot about NAT punch-through, so I imagine I might have to deal with that in the future, as I am using a router.. but hopefully I can get at least LAN working first.</div>

<div>&nbsp;</div>
<div>Thanks again!</div>
<div>Ben.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><br><br>&nbsp;</div>
<div class="gmail_quote">On Tue, Jun 3, 2008 at 11:38 PM, &lt;<a href="mailto:enet-discuss-request@cubik.org">enet-discuss-request@cubik.org</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Send ENet-discuss mailing list submissions to<br>&nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a><br>
<br>To subscribe or unsubscribe via the World Wide Web, visit<br>&nbsp; &nbsp; &nbsp; &nbsp;<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 &#39;help&#39; to<br>
&nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:enet-discuss-request@cubik.org">enet-discuss-request@cubik.org</a><br><br>You can reach the person managing the list at<br>&nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:enet-discuss-owner@cubik.org">enet-discuss-owner@cubik.org</a><br>
<br>When replying, please edit your Subject line so it is more specific<br>than &quot;Re: Contents of ENet-discuss digest...&quot;<br><br><br>Today&#39;s Topics:<br><br>&nbsp; 1. Re: &nbsp;[***SPAM***] &nbsp;Send client list to all clients (Ng Yao Kheng)<br>
&nbsp; 2. &nbsp;Managing peers on the server (Ben Johnson)<br>&nbsp; 3. Re: &nbsp;Managing peers on the server (Lee Salzman)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Tue, 3 Jun 2008 16:49:07 +0800<br>
From: Ng Yao Kheng &lt;<a href="mailto:ngyaokheng@hotmail.com">ngyaokheng@hotmail.com</a>&gt;<br>Subject: Re: [ENet-discuss] [***SPAM***] &nbsp;Send client list to all<br>&nbsp; &nbsp; &nbsp; &nbsp;clients<br>To: Discussion of the ENet library &lt;<a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>&gt;<br>
Message-ID: &lt;BAY120-W88C86B4D7D5A44F772CE1DEBA0@phx.gbl&gt;<br>Content-Type: text/plain; charset=&quot;gb2312&quot;<br><br><br>In Enet, how is bandwidth management done?<br><br>If not present, how is bandwidth management done for a game program?<br>
<br>Thanks a lot for your advise.&gt; Date: Tue, 27 May 2008 08:51:08 -0700&gt; From: <a href="mailto:lsalzman1@cox.net">lsalzman1@cox.net</a>&gt; To: <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>&gt; Subject: Re: [ENet-discuss] [***SPAM***] Send client list to all clients&gt; &gt; An enet packet is simply a piece of malloc&#39;d memory. You can stuff in&gt; whatever data you want into it. The peer -&gt; data field is not networked&gt; in any way, it is simply for your own internal usage.&gt; &gt; Lee&gt; &gt; Ng Yao Kheng wrote:&gt; &gt;&gt; &gt; Hi Williams,&gt; &gt;&gt; &gt; As I am quite new to network programming, can you give me a hint of&gt; &gt; how to achieve this? The ip address and the port number are integer&gt; &gt; and data in enet which is packet is string if I am not wrong......how&gt; &gt; can I send a series of ip address and port number to the client and&gt; &gt; then later interpret by the client correctly.....&gt; &gt;&gt; &gt;&gt; &gt; I had another problem:&gt; &gt; &gt;From client, I want to send to server a packet by following&gt; &gt;&gt; &gt; At client side,&gt; &gt;&gt; &gt; peer-&gt;data = &quot;SERVER2&quot;;&gt; &gt; int temp = enet_peer_send (peer, 0, packet);&gt; &gt; if!<br>
&nbsp;(temp == 0)&gt; &gt; printf(&quot;Send Successful %s\n&quot;, peer-&gt;data);&gt; &gt;&gt; &gt;&gt; &gt; At server side,&gt; &gt;&gt; &gt; case ENET_EVENT_TYPE_RECEIVE:&gt; &gt;&gt; &gt; printf (&quot;A packet of length %u containing %s was received from %s on&gt; &gt; channel %u.\n&quot;,&gt; &gt; event.packet -&gt; dataLength,&gt; &gt; event.packet -&gt; data,&gt; &gt; event.peer -&gt; data,&gt; &gt; event.channelID);&gt; &gt;&gt; &gt; the data in event.peer-&gt;data is null,....I receive the data but why I&gt; &gt; did not receive the string &quot;SERVER&quot; in event.peer-&gt;data????&gt; &gt;&gt; &gt; Please advise, thanks a lot&gt; &gt;&gt; &gt; Regards,&gt; &gt;&gt; &gt;&gt; &gt;&gt; &gt; ------------------------------------------------------------------------&gt; &gt; From: <a href="mailto:stevewilliams@kromestudios.com">stevewilliams@kromestudios.com</a>&gt; &gt; To: <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>&gt; &gt; Date: Tue, 27 May 2008 14:08:17 +1000&gt; &gt; Subject: Re: [ENet-discuss] [***SPAM***] Send client list to all&gt; &gt; clients&gt; &gt;&gt; &gt; There is no in-built method in enet to do that. In your code you&gt; &gt; would create a packet that contains the list of clients, and when&gt; &gt; a client connects to the host, the host would build the packet&gt; &gt; fr!<br>
&nbsp;om its own list of clients and send that packet to the new client.&gt; &gt;&gt; &gt; Steve &#39;Sly&#39; Williams&gt; &gt;&gt; &gt; Lead Programmer&gt; &gt;&gt; &gt; Krome Studios&gt; &gt;&gt; &gt; *From:* <a href="mailto:enet-discuss-bounces@cubik.org">enet-discuss-bounces@cubik.org</a>&gt; &gt; [mailto:<a href="mailto:enet-discuss-bounces@cubik.org">enet-discuss-bounces@cubik.org</a>] *On Behalf Of *Ng Yao Kheng&gt; &gt; *Sent:* Tuesday, 27 May 2008 1:57 PM&gt; &gt; *To:* <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>&gt; &gt; *Subject:* [***SPAM***] [ENet-discuss] Send client list to all clients&gt; &gt;&gt; &gt; Hi all,&gt; &gt;&gt; &gt; I am not sure if the mailing list is still active as my previous&gt; &gt; two mail were never answered.&gt; &gt;&gt; &gt; I have a question now and hope to receive an answer as my project&gt; &gt; is very urgent.&gt; &gt;&gt; &gt; Using enet, a client connect to server. When another client&gt; &gt; connect to the server, the server will have a list of 2 clients&gt; &gt; connected. Can I know of any idea how to replicate the client list&gt; &gt; to the client so that client can display a list of connected clients?&gt; &gt;&gt; &gt; Really appreaciate any reply. Thanks.....&gt; &gt;&gt; &gt; Best Regards,&gt; &gt;&gt; &gt; ------------------------------------------------------------------------&gt; &gt;&gt; &gt; Always-on security tool!<br>
&nbsp;s provide safer ways to connect and share&gt; &gt; anywhere. Find out more. Windows Live&gt; &gt; &lt;<a href="http://get.live.com/familysafety/overview" target="_blank">http://get.live.com/familysafety/overview</a>&gt;&gt; &gt;&gt; &gt;&gt; &gt; ------------------------------------------------------------------------&gt; &gt;&gt; &gt;&gt; &gt;&gt; &gt; This message and its attachments may contain legally privileged or&gt; &gt; confidential information. This message is intended for the use of&gt; &gt; the individual or entity to which it is addressed. If you are not&gt; &gt; the addressee indicated in this message, or the employee or agent&gt; &gt; responsible for delivering the message to the intended recipient,&gt; &gt; you may not copy or deliver this message or its attachments to&gt; &gt; anyone. Rather, you should permanently delete this message and its&gt; &gt; attachments and kindly notify the sender by reply e-mail. Any&gt; &gt; content of this message and its attachments, which does not relate&gt; &gt; to the official business of the sending company must be taken not&gt; &gt; to have been sent or endorsed by the sending company or any of its&gt; &gt; related !<br>
&nbsp;entities. No warranty is made that the e-mail or&gt; &gt; attachment(s) are free from computer virus or other defect.&gt; &gt;&gt; &gt;&gt; &gt; ------------------------------------------------------------------------&gt; &gt; Make the most of what you can do on your PC and the Web, just the w!&gt; &gt; ay you want. Windows Live &lt;<a href="http://www.get.live.com/wl/all" target="_blank">http://www.get.live.com/wl/all</a>&gt;&gt; &gt; ------------------------------------------------------------------------&gt; &gt;&gt; &gt; _______________________________________________&gt; &gt; ENet-discuss mailing list&gt; &gt; <a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a>&gt; &gt; <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a>&gt; &gt; &gt; &gt; _______________________________________________&gt; ENet-discuss mailing list&gt; <a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a>&gt; <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
_________________________________________________________________<br>Check out Barclays Premier League exclusive video clips here!<br><a href="http://fc.sg.msn.com/index.aspx" target="_blank">http://fc.sg.msn.com/index.aspx</a><br>
-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: &lt;<a href="http://lists.cubik.org/pipermail/enet-discuss/attachments/20080603/6838ba98/attachment.html" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/attachments/20080603/6838ba98/attachment.html</a>&gt;<br>
<br>------------------------------<br><br>Message: 2<br>Date: Tue, 3 Jun 2008 20:28:11 +1000<br>From: &quot;Ben Johnson&quot; &lt;<a href="mailto:bencelot@gmail.com">bencelot@gmail.com</a>&gt;<br>Subject: [ENet-discuss] Managing peers on the server<br>
To: <a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a><br>Message-ID:<br>&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="mailto:20a3ef50806030328k24dd98a5k13882915d0b449ad@mail.gmail.com">20a3ef50806030328k24dd98a5k13882915d0b449ad@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br><br>Hey all, first post!<br><br>I was looking around and Enet appears to be what I&#39;m after. I&#39;m making a<br>game using a server/client model, but there are a few things I&#39;m unsure<br>
about.<br><br>What is the best way to manage peers from the server end? So I can store<br>peers, and associate them with a particular player. Basically, when a player<br>joins the server, I&#39;d like the server to add this peer to a list, and assign<br>
it an ID so I can link it with a player. Then, when they disconnect, I&#39;d<br>like them to be taken off the list.<br><br>At first I tried making: std::vector&lt;ENetPeer*&gt; peers;<br><br>and each time a player joins, scanning through this vector, checking:<br>
if(peers[i] == NULL) peers[i] = event.peer;<br><br>thus replacing that peer. Then, when a peer disconnects, looping through<br>this vector, checking:<br>if(peers[i]-&gt;address.host == event.peer-&gt;address.host &amp;&amp;<br>
peers[i]-&gt;address.port == event.peer-&gt;address.port) peers[i] = NULL;<br><br>Then, the way I associate each peer with it&#39;s corresponding player object is<br>simply that they both share the same index in their respective vectors. So<br>
player[7] would belong to peers[7].<br><br>ANNYWAY.. this doesn&#39;t seem to be the best method. Because some people in<br>the archives have mentioned that the host actually has it&#39;s own list of<br>peers. And that it does all this for you? And that when a new peer connects,<br>
you can get the index of the new peer like:<br><br>case ENET_EVENT_TYPE_CONNECT:<br>int index = (int)(event.peer - host-&gt;peers);<br>...<br><br>So my questions are (there&#39;s a lot, I know.. sorry):<br><br>1) is my original way a good way? Or should I use host-&gt;peers instead?<br>
2) If I use host-&gt;peers.. will the host also manage the deleting of peers<br>when it gets a disconnect? If it does, does it rearrange the array? So if I<br>have 3 peersconnected, and then the 2nd one leaves.. will I still be able to<br>
access the third player with host-&gt;peers[2] or will it get dropped down to<br>the 2nd position at host-&gt;peers[1]? Furthermore, would it be best to save<br>the playerID into the data field?<br><br>3) Is the array size of host-&gt;peers set by the 2nd parameter in<br>
enet_host_create? So if I put in 64, will that mean 64 clients can be<br>connected at once?<br><br>4) I want my game to have a dedicated and a non-dedicated server option. If<br>it&#39;s non-dedicated, then you will control player[0]. Thus it would be<br>
convenient if I could also block off host-&gt;peers[0] (or my original<br>peers[0]) with a &#39;dummy&#39; connection to itself. Is this possible? Is it wise?<br>Like, upon creating the host, could I go:<br><br>if(!dedicated) host-&gt;peers[0] = enet_host_connect(host,&amp;address,2);<br>
<br>5) LAN vs Internet vs same computer. At the moment, all I&#39;m able to do is<br>get 2 applications on the same computer connecting. Is this because I&#39;m<br>using enet_address_set_host(&amp;address, &quot;<a href="http://127.0.0.1/" target="_blank">127.0.0.1</a>&quot;) when creating the server?<br>
If I wanted the server to be recognisable on LAN what address would I use?<br>How about the net? or both at the same time? Would I just use address.host =<br>ENET_HOST_ANY? If so, how do I know which IP to search for on the clients<br>
end?<br><br>Ok.. that&#39;s all for now. If you can answer any questions at all, that&#39;d be<br>great :)<br><br>Loving Enet so far, hopefully I can get past these basic concepts and get<br>into it more!<br><br>Thanks,<br>
Ben.<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: &lt;<a href="http://lists.cubik.org/pipermail/enet-discuss/attachments/20080603/62241372/attachment-0001.htm" target="_blank">http://lists.cubik.org/pipermail/enet-discuss/attachments/20080603/62241372/attachment-0001.htm</a>&gt;<br>
<br>------------------------------<br><br>Message: 3<br>Date: Tue, 03 Jun 2008 14:40:00 -0700<br>From: Lee Salzman &lt;<a href="mailto:lsalzman1@cox.net">lsalzman1@cox.net</a>&gt;<br>Subject: Re: [ENet-discuss] Managing peers on the server<br>
To: Discussion of the ENet library &lt;<a href="mailto:enet-discuss@cubik.org">enet-discuss@cubik.org</a>&gt;<br>Message-ID: &lt;<a href="mailto:4845BA30.6080001@cox.net">4845BA30.6080001@cox.net</a>&gt;<br>Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>There is a &quot;void *data;&quot; field in ENetPeer which ENet never touches, so<br>you can set it to whatever you want, i.e. it can point back to your<br>player structure.<br><br>The internal array of peers is fixed size and never reordered. When a<br>
client comes in the first available entry is used for the new<br>connection, but otherwise the same entry is always used for the duration<br>of the connection.<br><br>Yes, what you pass in to enet_host_create is the maximum number of peers<br>
it can support.<br><br>You can&#39;t assign an index in the peers array like you suggest. Just<br>don&#39;t do it. However, the first connection issued by enet_host_connect,<br>so long as no other connections have been created, is almost guaranteed<br>
to be put at peers[0].<br><br>If you want the server to be recognizable, don&#39;t use localhost as<br>address.host, it must either be an IP address that is guaranteed<br>recognizable from outside, or ENET_HOST_ANY to just take whatever IP the<br>
OS assigns, whichever. You must still give it a fixed port number, however.<br><br>Lee<br><br>Ben Johnson wrote:<br>&gt; Hey all, first post!<br>&gt;<br>&gt; I was looking around and Enet appears to be what I&#39;m after. I&#39;m making<br>
&gt; a game using a server/client model, but there are a few things I&#39;m<br>&gt; unsure about.<br>&gt;<br>&gt; What is the best way to manage peers from the server end? So I can<br>&gt; store peers, and associate them with a particular player. Basically,<br>
&gt; when a player joins the server, I&#39;d like the server to add this peer<br>&gt; to a list, and assign it an ID so I can link it with a player. Then,<br>&gt; when they disconnect, I&#39;d like them to be taken off the list.<br>
&gt;<br>&gt; At first I tried making: std::vector&lt;ENetPeer*&gt; peers;<br>&gt;<br>&gt; and each time a player joins, scanning through this vector, checking:<br>&gt; if(peers[i] == NULL) peers[i] = event.peer;<br>&gt;<br>
&gt; thus replacing that peer. Then, when a peer disconnects, looping<br>&gt; through this vector, checking:<br>&gt; if(peers[i]-&gt;address.host == event.peer-&gt;address.host &amp;&amp;<br>&gt; peers[i]-&gt;address.port == event.peer-&gt;address.port) peers[i] = NULL;<br>
&gt;<br>&gt; Then, the way I associate each peer with it&#39;s corresponding player<br>&gt; object is simply that they both share the same index in their<br>&gt; respective vectors. So player[7] would belong to peers[7].<br>
&gt;<br>&gt; ANNYWAY.. this doesn&#39;t seem to be the best method. Because some people<br>&gt; in the archives have mentioned that the host actually has it&#39;s own<br>&gt; list of peers. And that it does all this for you? And that when a new<br>
&gt; peer connects, you can get the index of the new peer like:<br>&gt;<br>&gt; case ENET_EVENT_TYPE_CONNECT:<br>&gt; int index = (int)(event.peer - host-&gt;peers);<br>&gt; ...<br>&gt;<br>&gt; So my questions are (there&#39;s a lot, I know.. sorry):<br>
&gt;<br>&gt; 1) is my original way a good way? Or should I use host-&gt;peers instead?<br>&gt; 2) If I use host-&gt;peers.. will the host also manage the deleting of<br>&gt; peers when it gets a disconnect? If it does, does it rearrange the<br>
&gt; array? So if I have 3 peersconnected, and then the 2nd one leaves..<br>&gt; will I still be able to access the third player with host-&gt;peers[2] or<br>&gt; will it get dropped down to the 2nd position at<br>&gt; host-&gt;peers[1]? Furthermore, would it be best to save the playerID<br>
&gt; into the data field?<br>&gt;<br>&gt; 3) Is the array size of host-&gt;peers set by the 2nd parameter in<br>&gt; enet_host_create? So if I put in 64, will that mean 64 clients can be<br>&gt; connected at once?<br>&gt;<br>
&gt; 4) I want my game to have a dedicated and a non-dedicated server<br>&gt; option. If it&#39;s non-dedicated, then you will control player[0]. Thus<br>&gt; it would be convenient if I could also block off host-&gt;peers[0] (or my<br>
&gt; original peers[0]) with a &#39;dummy&#39; connection to itself. Is this<br>&gt; possible? Is it wise? Like, upon creating the host, could I go:<br>&gt;<br>&gt; if(!dedicated) host-&gt;peers[0] = enet_host_connect(host,&amp;address,2);<br>
&gt;<br>&gt; 5) LAN vs Internet vs same computer. At the moment, all I&#39;m able to do<br>&gt; is get 2 applications on the same computer connecting. Is this because<br>&gt; I&#39;m using enet_address_set_host(&amp;address, &quot;<a href="http://127.0.0.1/" target="_blank">127.0.0.1</a><br>
&gt; &lt;<a href="http://127.0.0.1/" target="_blank">http://127.0.0.1</a>&gt;&quot;) when creating the server? If I wanted the server<br>&gt; to be recognisable on LAN what address would I use? How about the net?<br>&gt; or both at the same time? Would I just use address.host =<br>
&gt; ENET_HOST_ANY? If so, how do I know which IP to search for on the<br>&gt; clients end?<br>&gt;<br>&gt; Ok.. that&#39;s all for now. If you can answer any questions at all,<br>&gt; that&#39;d be great :)<br>&gt;<br>&gt; Loving Enet so far, hopefully I can get past these basic concepts and<br>
&gt; get into it more!<br>&gt;<br>&gt; Thanks,<br>&gt; Ben.<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>
&gt; ENet-discuss mailing list<br>&gt; <a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>&gt; <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
&gt;<br><br><br><br>------------------------------<br><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><br>End of ENet-discuss Digest, Vol 61, Issue 1<br>*******************************************<br></blockquote></div><br>