Jump to content
  • Advertisement
Sign in to follow this  
KKTHXBYE

ENET peer list?

This topic is 1032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can i store the peer in some kind of array when someone connects to the server (when peer connects to server)

 

becasue when client connects i can only access the poitner of that peer per one frame

while (enet_host_service (srv->server, & event, 0) > 0)
		{

		    if (event.type == ENET_EVENT_TYPE_CONNECT)
		    {

now event.peer is a pointer to ENetPeer

and i am not sure if that will get destoryed or i can store that pointer in the array for further things.

(i need to store the peer list so server can send data to all connected clients)

Share this post


Link to post
Share on other sites
Advertisement

I looked at a very simple program I have written using enet, I haven't use it extensively, so take it with a grain of salt.

 

That being said, have you tried using "enet_host_broadcast"? It is what I used and it worked fine.

Share this post


Link to post
Share on other sites
enet_host_broadcast will send a packet to the local network for everyone to receive if they're listening to it. I don't think that's what the OP wants.

The ENetPeer is the main connection object representing the "other end," so I imagine this is valid until such time that the connection goes away. I don't know what kind of notification you get when it becomes invalid, though.

Share this post


Link to post
Share on other sites

enet_host_broadcast will send a packet to the local network for everyone to receive if they're listening to it. I don't think that's what the OP wants.

The ENetPeer is the main connection object representing the "other end," so I imagine this is valid until such time that the connection goes away. I don't know what kind of notification you get when it becomes invalid, though.

 

Are you sure? I just tested here (server running on NY based VM, clients running on my machine).

This:

packet = enet_packet_create(buffer, strlen(buffer)+1, 0);
enet_host_broadcast(server, 1, packet);

And this:

for (i = 0; i <  ipeerCount; i++) {
    if (&server->peers[i] != event.peer) {
        packet = enet_packet_create(buffer, strlen(buffer)+1, 0);
        enet_peer_send(&server->peers[i], 0, packet);
        enet_host_flush(server);
    }
}

Both worked for the clients (I can paste the outputs here).

 

PS: I ommited the buffer value initialization.

Share this post


Link to post
Share on other sites

thats funny i reported that topic, because i found what to do, then i got -10 rep from the mod and he didint delete it, cool

 

btw i use the same code as 

KnolanCross

 

posted above

Edited by ?W ?I ?R ?E ?D ? ?C ?A ?T

Share this post


Link to post
Share on other sites

enet_host_broadcast(server, 1, packet);


Yes, this works if you want every client to get the same packet.
If you want to be careful about which client gets what packet, and you have more than one client, then this will not do that.

then i got -10 rep from the mod


I don't see anyone voting you up or down in this thread, so that's probably from somewhere else.
That being said: Don't worry about reputation in the short run. Everybody has up-ticks and down-ticks; good participation will lead to good reputation over time.
There is actually a slight negative correlation between worrying about reputation and actual reputation gain. I guess people don't like people who worry too much about it :-)

Share this post


Link to post
Share on other sites

yeah but i care because i can get -700 rep in matter of two hours, and there was no hint in that green box so i thought that was you

Share this post


Link to post
Share on other sites
Ha! I think I'm the mellowest of our mods here :-) I never down-vote a question, unless it's an obvious troll. I don't down-vote answers unless they are outright dangerous to follow, or go beyond the line of acceptable criticism.
That being said, I will close this thread, because I'm not interested in discussing ratings. Open a new thread if you have a particular new question you'd like to ask.

Share this post


Link to post
Share on other sites

This topic is 1032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!