While working on Twisted's networking, I discovered a series of differences between socket APIs on Windows and Unix/Linux. This article is intended to document them for the benefit of those who are developing their own networking code.
While working on Twisted's networking, I discovered a series of differences between socket APIs on Windows and Unix/Linux. This article is intended to document them for the benefit of those who are developing their own networking code.
While working on Twisted's networking, I discovered a series of differences between socket APIs on Windows and Unix/Linux. This article is intended to document them for the benefit of those who are developing their own networking code.
The permanent home of this article will be on my homepage, where I will add anything new I discover or I receive from other people. Please add comments to the article if you know of any other differences.
Some caveats:
My main sources of information were the relevant MSDN pages, Volume 1 of Unix Network Programming (2nd Edition), and experimentation and results from running systems. I recommend all three for verifying this information.
Without further ado, here are the differences (I may have forgotten some):
I think to utilize the full power of Win32 networking, one would use the WSA Event methods and work with the normal event functions, and not use the berkley wrappers.
This will also support threaded parallel usage of Overlapped IO completion. How about using them in the Framework?
I wrote code for this a while back, but never finished it for lack of interest, time and a real Windows machine. Plus we had a lot less tests at the time, and non-finalized APIs, so finding where the bugs were was hard. It was basically working though.
At some point we will have this (faster if someone pays me, donates a MSDN subscription or writes it themselves ;). But until we do, working code is better than no code.
For many people, porting their BSD socket code will be much easier than rewriting, and thus this article.
The real point of this article, of course, is:
Do Not Write Your Own Portable Networking Layer.
It is fairly difficult and subtle to get networking code to work even with the BSD wrappers on Windows. A network layer, even one that is only portable between different UNIXes, requires considerably more effort than reading a few pages of UNP and the man page for socket(2).
Twisted, hopefully, will have support for the more advanced IO completion facilities on Win32 (and, for that matter, the aio facilities on linux), but in the meanwhile, if you are trying to write a portable network application, consider donating some porting effort to an existing framework rather than writing one from the ground up.
If Python isn't to your taste, I've heard a few good things about gnet. Of course, I have a bias, but I think you should use Twisted.
...the Cygwin people have also tackled such problems before.
Link: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/
Warning: Whle this is very easy to use, readability is chosen over speed, and it as yet hasn't been tested for security.
The Python socket module source code is probably an excellent guide.
Quinn, Bob, and Dave Shute. Windows Sockets Network Programming. Addison-Wesley, 1996. ISBN: 0-201-63372-8
It covers Winsock 1.1 and 2.0, differences (and porting from) BSD sockets, etc.
New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!