Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Networking libraries?

This thread is locked; no one can reply to it. rss feed Print
Networking libraries?
Mark Oates
Member #1,146
March 2001
avatar

Hey all, I'm looking to beef up my networking features for gaming or otherwise as it's becoming more clear to me that having networking/multiplayer in apps is a bit more critical these days. I'd like to use a library and am looking for suggestions.

I'm not very familiar with the topologies for how networking programs work (server?, host?, client? host always running maintains a client list? two nodes connect directly 1:1? wake on lan?)

There are two libraries that I'm aware of: Boost ASIO, and enet. I feel like Enet is the professional solution, but I'm a bit turned off by the requirements for build (windows requires downloading a dll, etc). I'd like for this to be easily buildable.

In the past (2015 wow that was a long time ago), I used Boost ASIO for a project called "flare_network" as part of exploration. I'll need to look back into that and see if it's still feasible. Taking the Boost route sounds very manual (which is fine, but it would be nice to see this feature out sooner than later), and also the common concern of Boost as a dependency is not good. (But, I'm just reading now, it looks like most of ASIO is part of std since C++11).

Regardless, doing ASIO manually with no experience I feel like I'm just opening up a can of worms for edge cases that I have no idea could even exist. Or not, maybe it's not that hard.

Any of you guys have experience or recommendations on what routes to take?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

jmasterx
Member #11,410
October 2009

depends on your needs, and your tolerance to latency.

anything TCP is simplest to deal with but it's much slower due to acks.

pure UDP is fast but unreliable, so most solutions involve some hybrid of the two.

ENet or RakNet work just fine for many general applications - the question becomes, if a client loses connection due to wifi/unstable connection, how do you resync them? If it's a shooter, you need a way to know who was right (latency compensation), so it quickly becomes a complex problem. In fact, a simple web socket library can probably handle a lot of use cases, it's more about how you deal with sessions, latency, etc that's application specific and can be challenging.

Some games go as far as to have the server replay the simulation to know the ground truth of what really happened.

The most basic form of a game server is just message passing really.

My game Stemwater Spades features a fully implemented lobby, client server model, and authentication with a central login server, and it never trusts the client. It has its own message system. You can use something like protobuff but I enjoyed doing it myself It might be helpful:
https://github.com/jmasterx/StemwaterSpades/blob/master/Spades%20Game/Game/Net/ServerCore.cpp

you can branch around from there, there's a lot of files.

If you have questions about the code, I might remember how it works but it's been a while ;)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

If you're satisfied with TCP wrappers you can try Gully's code from his networking library Nilorea (https://www.allegro.cc/forums/thread/618081 ). I'm using it currently, and I made some nice C++ wrappers around a basic Client / Server / Network class.

Also, building enet static is easy. It's a one line addition to their CMake file. I changed that a long time ago. 8-)

Mark Oates
Member #1,146
March 2001
avatar

It's a one line addition to their CMake file. I changed that a long time ago. 8-)

Nice. Did you get a commit on ENet? :D

Quote:

If you're satisfied with TCP wrappers

To be completely honest, I'm still not 100% on TCP, HTTP, and TLS (are there any others?).

My thought, was that TCP was the fire-it-and-forget-it message type. That's the one I'm going for. I can figure out alternative ways to make those data packets sync and communicate, so I don't want to get more complicated than that.

jmasterx said:

anything TCP is simplest to deal with but it's much slower due to acks.

Interesting. I always thought TCP (was|would be) the fastest. I tried it over an ngrok connection. It's a lot slower than I expected. localhost speeds is basically what I'm looking for.

Quote:

The most basic form of a game server is just message passing really.

Ok. That sounds good.

Alright, I have a really cool breakthrough for sure. I managed to pull my old https://github.com/MarkOates/flare_network project and built without error right out of the box on my Mac.

I converted the project and removed the boost dependency. Now, the dependency is only a cloned repo of asio. It builds on Windows now, too (but I have a problem with the client executing, keep getting a "Exception: resolve: No such host is known." on win when not using localhost). So major progress. Definitely usable primitives to do what I plan to do.

It's basically a silent server program (shows connect and disconnect messages when running) that relays basic messages, and a client program that you type into std::in and after pressing ENTER, will send the message to the server. The client also receives and outputs all messages relayed from the server.

I've tried it on localhost (works on Mac and Win), and tried it connecting over a ngrok tcp tunnel (works on Mac). I had my laptop sending messages to my MacMini and vice versa. Next steps would be to componentize the class, and extract it from the entry point main, and add tests.

Legit though, I'm drinking a glass of wine to this. I consider this a huge success.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

jmasterx
Member #11,410
October 2009

localhost speeds is basically what I'm looking for.

Over the internet ? I don't think so hahah...

GullRaDriel
Member #3,861
September 2003
avatar

HTTP/HTTPS and TLS are protocols over TCP IP.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Rodolfo Lam
Member #16,045
August 2015

Oh!, do try LibPoco. I know you use C++ so you will be right at home. They are open source and feature some really neat extras. The website is right here.

POCO is very network focused. And their aim is to provide easy network capabilities to C++ programs. You have raw UDP and TCP ports, HTTP servers, Database connections, and many other things.

GullRaDriel
Member #3,861
September 2003
avatar

Okay Mark:

TCP-IP is the transport protocol. Anything else on top of it is using basic connect/accept send/recv.

HTTPS/SSL are encrypted protocols over tcp ip. What I stated before is true.

For your needs you'd better stick to enet/known equivalent or even parts of my lib. You can cannibalize it to just use what you need.

Let's warn you: cross platform networking and encapsulation are pains. When you'll be there we will talk about dead reckoning algorithms and such.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: