Winsock Core API

Overview

The Winsock (Windows Sockets) core API provides the fundamental networking primitives for creating TCP/IP and UDP/IP client and server applications on Windows. It follows the Berkeley sockets API with Windows‑specific extensions.

Key Functions

FunctionDescriptionHeader
WSAStartupInitialises the Winsock library.winsock2.h
WSACleanupTerminates use of the Winsock library.winsock2.h
socketCreates a new socket descriptor.winsock2.h
bindAssociates a local address with a socket.winsock2.h
listenMarks a socket as a passive listening socket.winsock2.h
acceptAccepts an incoming connection request.winsock2.h
connectEstablishes a connection to a remote socket.winsock2.h
sendSends data on a connected socket.winsock2.h
recvReceives data from a connected socket.winsock2.h
sendtoSends a datagram to a specific address.winsock2.h
recvfromReceives a datagram and captures its source address.winsock2.h
getsockoptRetrieves a socket option value.winsock2.h
setsockoptSets a socket option value.winsock2.h
closesocketCloses an existing socket.winsock2.h
selectMonitors multiple sockets for readiness.winsock2.h

Common Structures

Important data structures used with the Winsock API:

Typical Initialization Pattern

WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (result != 0) {
    printf("WSAStartup failed: %d\n", result);
    return 1;
}

/* ... socket operations ... */

WSACleanup();

Reference Links

Explore detailed documentation for each area: