Traditional Sockets

Two types of sockets are in general use: TCP sockets and UDP sockets (SOCK_STREAM and SOCK_DGRAM respectively). A “raw” socket is also available that is used for specialized applications such as “ping” and “traceroute” (tracert).

In the beginning, the network programmer had to deal with the structures in Listing 12.1 just to establish a connection.

Listing 12.1. socket Address Structures
 struct sockaddr { unsigned short sa_family; // address family, AF_xxx char sa_data[14]; // 14 bytes of protocol address }; struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // Same size as struct sockaddr } ; struct ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.