[ENet-discuss] ENet-discuss Digest, Vol 61, Issue 1

Ben Johnson bencelot at gmail.com
Tue Jun 3 07:01:35 PDT 2008


Wow, thanks for the fast reply.

You cleared up quite a bit of my confusion, too.

I ditched my vector of peer pointers, and am now using the host->peers
instead.
Also, instead of using a dummy connection when I want to play
on non-dedicated server, I do something like this:

maxPlayers = 12;
if(!dedicated) maxPlayers--;
host = enet_host_create(&address, maxPlayers, 0, 0);
serverPlayer = maxPlayers;

this will only allow for 11 other players to join. And they will fill spots
0 to 10 in the host->peers array.
The player the server now controls is player[serverPlayer] - which is the
12th and final player. So I don't have to worry about it being replaced,
etc..

Hooray, first 4 questions solved!

As far as question 5 goes, I'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's address to ENET_HOST_BROADCAST, and that will return
any server addresses? I tried, but it didn't work.. Do I have to connect
twice or something? Once to find the address, and then again to connect to
it?

Also, can a server host for both LAN and the internet at the same time? So
anyone can join, whether they'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've got both the LAN connection and the internet connections working
properly. I'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.

Thanks again!
Ben.







On Tue, Jun 3, 2008 at 11:38 PM, <enet-discuss-request at cubik.org> wrote:

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


More information about the ENet-discuss mailing list