Archived

This topic is now archived and is closed to further replies.

Networking in Linux/Windows

This topic is 6361 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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; (<

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, ignore the smileys, I intended to write a semicolon followed by a parenthesis, not a winking smiley...

Share this post


Link to post
Share on other sites