Skip to main content
GameDev.net gamedev.net
🔒 Locked

WinSock vs unix sockets

Started by Quat Dec 28, 2005 at 12:38 PM 2 replies 8.4k views
Original Post
Quat
Quat
Hi, I want to start learning the basics of network programming. It sounds like for Windows WinSock is the way to go, or one of the higher level libraries. I spent some time researching books and there does not seem to be any up to date or good books on WinSocket--most got negative reviews. However, I have seen some good rated unix socket book reviews such as "Unix Network Programming, Vol. 1: The Sockets Networking API." From what little I've gathered, unix sockets is almost the same as WinSocket, just different implementations of the same API? So my question is: would it be possible to learn from a unix socket book and easily port to WinSockets?
-----Quat
Zao
Zao
If you want to, as long as you initialize the WinSock2 api, all the other functions such as recv, send, socket and all of those are practically identical to the unix sockets.

WinSock2 has some neat extra features such as Asynchronous sockets and things like that, but you can code blissfully like it was unix if you want.

If you want to write something with high performance with many sockets, look into IO Completion Ports. That's a windows-specific way to effectively monitor files and sockets, but is a bit messy to learn.

One difference you might want to know is that select has a much lower maximum of sockets it can poll than in unix. The exact numbers should be in MSDN somewhere.

The forum FAQ here probably can tell you much about sockets as well :)
To make it is hell. To fail is divine.
hplus0603
hplus0603
I second looking at the Forum FAQ. Also, the sockets API is small enough that you don't really need a book for it; a tutorial + man pages (or MSDN pages) should be sufficient.

Note that high-performance sockets programming varies between OS-es; on Windows, you use Windows-specific calls; on Linux, you use Linux-specific calls; on Solaris, ... well, you get the idea. High-performance socket programming is much harder to find books or tutorials about, because you're assumed to know how to read documentation / man pages when you get to that level of need.

If you're intending to serve no more than, say, 20 clients at the same time, which sockets API you're using will probably not matter anyway.
enum Bool { True, False, FileNotFound };
HyperLiu
HyperLiu
Quote:

From what little I've gathered, unix sockets is almost the same as WinSocket, just different implementations of the same API?


The WinSock is almost the same with unix socket expect it must invoke the WSAStartup to initiate the WS2_32.DLL. All the usage of the functions in the unix sockets like socket, bind, connect, accept, sned and recv are all the same with WinSock.

I think the major difference between WinSock and BSD socket is that WinSock provide the Asynchronous Mode ,Overlapped I/O and IOCP (only for Windows 200x). If you don't use these functions, you can use WinSock just as you are using BSD socket :->.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.