Skip to content
Search

WSAStartup

lastmod 2018-08-17created 2018-08-072 edits

How to initialize Win32 sockets.

How to use

Use WSAStartup() to initialize sockets, as follows.

WSDATA ws;
WSAStartup(MAKEWORD(2, 2), &ws);

Once initialization succeeds, create a socket. The relevant function is socket.

SOCKET _socket;
_socket = socket(PF_INET, SOCK_STREAM, 0);

MSDN says either AF (address family) or PF (protocol family) can be used as the first argument of socket, but for issues regarding correct usage, see here.

Finally, release the socket. Use WSACleanup() to release it.

WSACleanup();

See also