ENET peer list?

Started by
6 comments, last by hplus0603 8 years, 7 months ago

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)
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.

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

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.
enum Bool { True, False, FileNotFound };

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.

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

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

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 :-)
enum Bool { True, False, FileNotFound };

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

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.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement