Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross platform simple TCP/ IP API?

Tags:

c++

I'm making a simple cross platform chat program. I'm using wXWidgets for the GUI which works well, but I need a way to create a socket and to create a server client setup. Is there an API that for example underlying uses WinSock on Windows, and Linux's native socket and osx's?

I'm not looking for boost as a solution because I will be making it open sourced and not everyone feels like installing a 70+ MB library.

like image 645
jmasterx Avatar asked Nov 21 '10 00:11

jmasterx


3 Answers

Winsock is quite compatible with the POSIX socket APIs, and most of the standard functions are available in both. The headers are named differently, but a simple #ifdef can solve that:

#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
// other headers you may use
#endif
like image 67
casablanca Avatar answered Nov 09 '22 11:11

casablanca


The QtNetwork module

like image 24
hhafez Avatar answered Nov 09 '22 12:11

hhafez


wxWidgets itself has TCP client/server classes: see here

like image 36
HighCommander4 Avatar answered Nov 09 '22 11:11

HighCommander4