Sign in to follow this  

ENET peer list?

This topic is 819 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
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

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
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 819 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