On Windows, instead of the inclusions you mentioned should be enough:
#include <winsock2.h>
#include <windows.h>
You will also have to link to ws2_32.lib. It is disgusting to do it this way, but for VC ++ you can do it through:#pragma comment(lib, "ws2_32.lib")
Some other differences between Winsock and POSIX include:
WSAStartup() .
close() closesocket().
int typedef SOCKET, . - -1 , Microsoft INVALID_SOCKET, .
, , ioctlsocket() fcntl().
send() recv() write() read().
, Linux, Winsock... , . , , #ifdef s..
:
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
typedef int SOCKET;
#define INVALID_SOCKET ((SOCKET)-1)
static inline int closesocket(int fd) { return close(fd); }
#endif
, - , , , , .