Jump to content
  • Advertisement
Sign in to follow this  

Enet and general networking help

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

Hi, This is my first attempt at a network game. I've decided to use ENet. Since this is mostly a learning experience i'm not going to care about speed or good synchronisation or prediction or security or those other things i've heard talked about. I'd like to not have a central server, except a simple PHP script which can be requested, this will log the IP and reply with a list of recent IPs, which the player can try to connect to. Each player will simulate themselves and send their positions to the others at some intervals. A player joining the game will request from one IP a list of all others in this game. He will then signal to each that he has joined the game, so they know to send him positioning info etc... ANYway, I hope that sounds workable. Onto my main questions regarding enet. (I've been reading http://enet.cubik.org/Tutorial.html) 1) I am confused by the distinction between a server and host. I visualise a server as in most games, a central machine. But here I want each peer to be their own player server. So do I set up Enet so each player is a server with "enet_host_create", and for each player use "enet_host_connect" to connect to all others? But if one player "enet_host_connect"s to another and vice versa, then there are two connections between them, is this okay? Or should there just be one? 2) "peer" in ENet terminology. Does this include the server? For each player do I: - create as enet server - connect to all other IPs, as these are all peers despite being servers - start main loop with a "enet_host_service" switch This seems as arcane as when I was trying to use ODE for the first time. But I managed that! So hopefully I will understand networking and ENet at some point. Also if there is any sample code using ENet that would be interesting! Thanks, Dan

Share this post

Link to post
Share on other sites
A "host" refers to the endpoint on a network (ie. the application running on the machine). A server is more of a higher level idea, where a single host services many remote clients. In ENet, a "peer" is a remote host.

Since a host is any machine on the network, you will call enet_host_create on both client and server. However, on the server you will call enet_host_create with a local address to bind to (ie. your listen port). On the client, you won't specify an address or port, but you will call enet_host_connect to connect it to the server host.

ENet is not restricted to pure client/server and allows you to do peer to peer (client/server is sort of a special case of peer to peer where all peers connect to a single peer - the server).

So for client/server:

1. create_host on server, binding to port.
2. create_host on client, without binding to any specific port (pass NULL as the first parameter).
3. host_connect, passing in the target address/port.

Peer to peer is exactly the same except in part 2, you would beind to a port so others can connect. Be mindful of parameter two of create_host which restricts the number of peers connected to a single host at one time.

That tutorial you linked is what I went off, and I made a C++ enet wrapper which makes things much nicer to deal with :).

One other thing: Since enet is purely UDP based, you won't be able to use it to connect to an HTTP server (which uses TCP). You could use a standard socket to query the PHP, and enet to connect to the hosts for gameplay.

Share this post

Link to post
Share on other sites
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!