views:

227

answers:

8

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.

Thanks

+2  A: 

most of the berkeley sockets api works everywhere.

GregS
A: 

I've got a feeling the Apache Portable Runtime might help with what you're looking for. Apache HTTPD used this library internally to abstract its platform-specific code so that the server code focuses on the logic and calls the methods in the APR and these translate to underlying operating system functions.

Of course, it might have more tools in it than you strictly need...

Ninefingers
Have you looked at the APR? It is huge and complex.
Byron Whitlock
On Huge - True but then that's a necessity to provide abstraction from the OS API - so is Java, really, or .Net. On complex - no more so that the alternatives. As pointed out in another answer, APR provides some excellent threading apis as httpd has tested this space extensively.
Ninefingers
+1  A: 

The NRL has a really great library of networking methods that supports a large variety of platforms. They have excellent support from the actual developers on their mailing lists as well.

Protolib

Harley Green
+1 From me, that looks really good!
Ninefingers
+2  A: 

You can use ACE or Boost.Asio:

About ACE:

Increased portability -- ACE components make it easy to write concurrent networked applications on one OS platform and quickly port them to many other OS platforms. Moreover, because ACE is open source, free software, you never have to worry about getting locked into a particular operating system platform or compiler configuration.

About boost:

Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

Alok
A: 

Synapse is good multiplatform network library. Open source and very easy to use.

http://www.ararat.cz/synapse/doku.php/download

Massimo Fazzolari
+3  A: 

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.

0xfe
A: 

SDL Net is a very simple abstraction layer on top of sockets, that's very easy to use. See http://www.libsdl.org/projects/SDL_net.

small_duck
+1  A: 

For this simple application you can use the standard "Berkeley socket" functions that are mostly portable. You can also use Boost's abstractions.

If you needed security functions like SSL/TLS (which you don't need for a simple game I guess), there are open source libraries like OpenSSL, GNU TLS, Mozilla NSS.

AndiDog