Microsoft Docs

Documentation for Windows Development

Winsock API Reference

This section provides detailed documentation for the Windows Sockets API (Winsock), a programming interface that allows applications to communicate over a network. Winsock is Microsoft's implementation of the Berkeley Sockets API, providing a standardized way for Windows applications to access network services.

Introduction

The Windows Sockets API (Winsock) is a set of C language functions that enable Windows-based applications to communicate over a network. It supports both TCP/IP and other networking protocols. Winsock is essential for developing network-aware applications, including web servers, clients, email programs, and more.

Core Concepts

Functions

The Winsock API includes a comprehensive set of functions for network programming. These functions can be categorized as follows:

Address Resolution

Connection-Oriented Protocols (e.g., TCP)

Connectionless Protocols (e.g., UDP)

Error Handling

General Socket Operations

I/O Multiplexing

Network Management

Protocol-Specific Controls

Security

Service Providers

Transport Data Transfer

Structures

Key structures used in Winsock programming:

Name Description
SOCKADDR Generic socket address structure.
SOCKADDR_IN Structure for IPv4 socket addresses.
SOCKADDR_IN6 Structure for IPv6 socket addresses.
WSADATA Structure containing information about the Winsock implementation.
FD_SET Set of socket descriptors used with select.
TIMEVAL Structure for timeout values.
HOSTENT Structure containing host information.
SERVENT Structure containing service information.
ADDRINFO Structure for results of getaddrinfo.

Constants

Important constants and macros used in Winsock:

Error Codes

Common Winsock error codes returned by WSAGetLastError:

For a comprehensive list, refer to the Windows Sockets Error Codes page.

Tutorials and Samples

Explore practical examples and tutorials to learn how to use Winsock effectively: