I was wondering if there was an API to do networking that would work on Windows, Mac and Linux. I would like to make a card game that 2 people can play through a TCP connection.
Generally cross platform libraries are implemented in layers. There is the public interface, the common code, and a minimalized set of platform dependent code. The public interface usually uses #if defined(symbol) checks to determine which platform it is running on.
cpp-netlib is a collection of network-related routines/implementations geared towards providing a robust cross-platform networking library.
There are a few options for this, some easier to use than others:
APR (Apache Portable Runtime) - Very popular. Quite easy to use. Includes lots of additional features handy for network programming (threads, mutexes, etc.)
ACE - Popular among the embedded space. Personally, I found it quite a complicated API, and not very straightforward to use.
Boost - If you have a decent level of sophistication with C++ (templates, metaprogramming, etc.), then Boost libraries are generally very good. I'm not sure how popular the Boost asynchronous networking libraries are in the real world.
QT - Popular as a UI toolkit, but has a great set of threading, event management, networking libraries. IMO, this is by far the easiest to use.
It's important to stay away from using the berkeley sockets library, as the implementations across operating systems vary wildly, and you'll lose a fair bit of time to tuning them as you port your software across OSs.
My personal preference: APR.
most of the berkeley sockets api works everywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With