I'm making a simple cross platform chat program. I'm using wXWidgets for the GUI which works w开发者_Python百科ell, 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.
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
The QtNetwork module
wxWidgets itself has TCP client/server classes: see here
How about Apache Runtime? Here is the page detailing socket definitions:
http://apr.apache.org/docs/apr/trunk/group_apr_network__io.html
I'm answering this seven years old question in the hope that this helps someone, someday (:
I have failed to find a cross-platform, lightweight API on sockets. (There is poco, boost asio and others out there, but they are big, comprehensive and complex libraries)
So I made a simple (and not complete) wrapper on POSIX sockets and Winsock here: https://github.com/soroush/libcpnet
精彩评论