Advertisement

Multiplatform Development - Winsock and BSD

Started by August 22, 2003 12:28 AM
3 comments, last by deepdene 21 years, 5 months ago
Basically I am developing a server at the moment on the windows platform, but I''m wanting to give it multiplatform ability to run on the UNIX style platforms. What are the imcompatibilities when it comes to winsock and BSD sockets. Like I know that you have to call closesocket on winsock instead of close, INVALID_SOCKET doesn''t exist on BSD sockets etc. What are the common pitfalls?
The toughest thing you will run into is the fact that what runs well on one system might crawl on the other. Both platforms do the operations differently. Threads and processes in Unix aren't that harsh but spawning a new thread or process under windows will be very slow.

Windows has IO Completion Ports which is supposed to be the most scalable networking option out there and Unix does not.

Aside from that then you are only going to run into small differences. There is the
WSAStartup stuff you have to do on Windows,
Declaring winsock.h, etc

On unix you will find the need for many more include files than just sockets.h. Not a big deal.

Just stay away from any WSA calls (Windows specific) and you should find the code ports over very easily. Even if you use threads there is only a little difference between a call to Window's CreatThread(...) and Unix's p_thread_create(...) functions.

It's the behind the scenes stuff that will get you.

Edit* More thoughts: INVALID_SOCKET is just a definition used by Windows. Basically it is equivalent to a 0, 1, 2 or some other number. Unix sockets will return some equivalent value that you can check. If you are realy attached to INVALID_SOCKET then just find out the return code under BSD and do a
#define INVALID_SOCKET (return code number) then voila!

Webby

[edited by - websitewill on August 22, 2003 7:40:52 AM]
Advertisement
I''m currently working on the same kind of project (MORPG server). I''m leaning towards using a library (something like SDL_net). There''s a lot of them out there. I would recommend that you abstract whatever you use so that it can be easily replaced.

In my case, I''m going to use SDL_net to get things rolling, and then replace it later (since I don''t want to HAVE TO release the source for my project). I may do so, but I don''t want to be required to by SDL_Nets GPL license.

bpopp (bpopp.net)
Hello deepdene,

One thing you definitely what to do is get a cross platform threads class, because you don''t what to have to have #ifdef all over for thread calls.
We use JTC threads library, it free to use and source is out there on net. It interface is almost like JAVA (JTC is JAVA like Threads for C++). It works very well, we have it running in DEC, SUN and PC.

The one think I like about Unix systems is socket and file descriptors are pretty much treated alike.
bpopp is right about abstracting your networks stuff so you can change library use. I have heard and SDL_net, I have heard about ACE which is cross platform and very robust. I wish we used a cross platform lib in or code, but we have good home grow classes.

Lord Bart
Thanks very much for the quick responses.

This topic is closed to new replies.

Advertisement