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


Can I port Windows - winsock-server to Linux platform???

Recommended Posts

Hi! I`m in a position where I need to build a server -using winsock WIN32 APi - and be sure that I can port it to Linux in the future,,Is it possible without major implemenation changes ? /Stefan E. Newswede Developer

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
This question seems to be asked often, and the answer is quite simple. If you write server code that is strictly conforming to the established standards, which doesnt include any DirectX or Win32 code then you should be fine. It would be a good idea to read through beej''s network programming guide at, because it has good reliable information and it tells you exactly the differences between the mainstream unix implementation of sockets and the microsoft implementation. There are however differences that could cause problems, so if your project is quite large you might benefit from writing a small interface library which you can re-code for each platform you intend to support. You could also use the precompiler to help you out, for example, directives like:

#ifdef WIN32
// Win32 code here
// Non-win32 code here

You should also remember that portability can be a sacrafice especailly in alot of purposes where the server is not going to be distributed anyway and you already know what platform you will be running on. For example, MMORPG games and the like, if this is the case then you may like to take advantage of platform-specific extensions. For example, linux has quite sophisticated asynchrounous i/o reading and writing support to sockets, and windows also has its specail i/o functionality. They both essentially do the same thing, but attempting to support them both is only really possible with alot of knowledge of both systems and a good library to stick between your application and the operating system. I recommend you decide exactly what platforms you will be supporting from day 1, and then stick to it. If you are supporting multiple platforms then my suggestion of building a portable high-performance network library may come in handy. If the server is to only run on one platform you dont have to worry much and you can pretty much use whatever facilities of that OS you wish.

Let me also say that supporting Linux is only really possible if you have a linux machine to the spare. It is also the norm in linux to distribute the sources with any binaries that you produce to allieviate problems in library dependancies. If you are distributing binaries, or just sources you should also keep in mind that linux runs on more than just PC hardware. It has ports to many others including the PowerPC (which typically runs Macintosh) and SUN''s Sparc64 platform. The former has a different endian order which complicates things such as sending integers over the network, and the latter is a 64-bit platform which means all pointers are 64-bits in length and it supports the long 64-bit integer natively. That being said, you can quite easily support linux on the x86 (Intel 386/486/Pentium) quite easily by sticking to conforming standards or writing a network library to abstract the network functions.

Good luck!

Share this post

Link to post
Share on other sites