Prabakaran Blogs

Porting Unix Socket code to Windows

Windows sockets and UNIX type berkeley sockets provide pretty much similar interface which eases the porting effort. Apart from regular network system calls such as socket(), bind(), listen(), accept(),etc two API calls are important in Windows sockets

WSAStartup()-> should be called before calling any other winsock APIs

WSACleanup()-> should be called when program exit

After a socket connection is established, data can be transferred using the standard read() and write() calls as in UNIX sockets. Sockets must be closed by using the closesocket() function in Windows instead of close() in case of Windows.

Header File:

winsock2.h

Library:

Ws2_32.lib

Alternatively, you can add below line to header file

#pragma comment(lib, “Ws2_32.lib”);

More information on this topic can be found here @ msdn

June 24, 2011 Posted by | OS | , | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.