Networking in Linux/Windows
Well, I've written a networking library which is source portable between Windows and *nix. I don't know of anything other than sockets/Winsock that can let you do this.
The main difficulty I had was figuring out a source portable async recv/listen(for TCP mode). My current(kludgey I feel) solution is to use the blocking semantics(identical behaviour on both platforms) and just spawn some threads that can be blocked(I ended up writing some posix threading emulation for Windows so that would cross compile, not hard for just thread creation and mutexes, it was about 5-7 functions).
Here's the winsock/sockets macros I used to help me:
#ifdef WIN32 // Windows#include <winsock.h>#define readsocket(a,b,c) recv(a,b,c,0)#define writesocket(a,b,c) send(a,b,c,0)#else // BSD(everyone else)#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#define readsocket read#define writesocket write#define closesocket close#define INVALID_SOCKET -1#define SOCKET_ERROR -1#define SOCKET int#ifndef INADDR_NONE#define INADDR_NONE ((unsigned long) -1)#endif#endif
P.S. Yes, those header files should have angle brackets, but stupid HTML wouldn't work. If someone would care to share how to make those nifty code boxes, I'd be much obliged.
P.S.S. Thanks Mr. Anonymous poster , as you can see, fixed, oh yeah, to the dude who made the original post, you can email me for more info if you'd like.
Edited by - Dogfood on July 17, 2000 3:35:27 PM
Edited by - Dogfood on July 17, 2000 5:50:14 PM
[ source ]
Your code goes here
[ / source ]
but without any spaces between the brackets the slash and "source", and it will look as follows...
Your code goes here
Also to get angle bracket without doing that write > (> or < (<