🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Networking in Linux/Windows

Started by
2 comments, last by MadCow[an] 23 years, 11 months ago
I''m developing a game engine (and ultimately a game) -- really just seeing what I can do, and so far I''m very pleased with the results. Something I want to add is networking capabilities. At the moment the engine runs perfectly in both Linux and Windows, and ideally I want to keep it that way. Are there any APIs which would allow the networking code to be pretty much identical on the two platforms, or am I going to need to use Winsock for Windows and something else for Linux? Having said that, how on earth do you program network code for Linux -- I''ve read a few articles on Winsock -- where can I get info about network code in Linux (I hope it''s friendlier than winsock!) Thanks, Douglas Cowan
Advertisement

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
Write

[ 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 &gt; (> or &lt; (<
Ok, ignore the smileys, I intended to write a semicolon followed by a parenthesis, not a winking smiley...

This topic is closed to new replies.

Advertisement