TCP Socket
TCP Socket
CS3214 Instructors
Virginia Tech
Question:
How does process A on host H1 communicate with process B on host H2 ?
Internet
Ethernet
R1 191.23.25.193 LAN 1
60 Machines
PPP Link 2
191.23.25.192/30 Subnet address:
191.23.25.197 R2 191.23.25.128/26
Default gateway:
191.23.25.194 191.23.25.129
R3 Ethernet
191.23.25.198
LAN 2
120 Machines
191.23.25.1
Subnet address:
191.23.25.0/25
Default gateway:
191.23.25.1
first introduced in BSD 4.1 Unix (1981), now de facto standard on all platforms
as a general interprocess communication (IPC) facility:
a host-local, application-created, OS-controlled interface (a “door”) into which application
process can both send and receive messages to/from another application process
when used for network communication:
a door between application process and end-to-end transport protocol (UDP/TCP)
in Unix, sockets are file descriptors, so read(2), write(2), close(2) and
others work
Bindings exist in many higher-level languages: e.g. java.net.Socket, Python
socket
Usage:
int socket(int domain, int type, int protocol);
Usage:
int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
/* IPv6 address */
struct in6_addr {
union
{
uint8_t u6_addr8[16];
uint16_t u6_addr16[8];
uint32_t u6_addr32[4];
} in6_u;
};
Good News
RFC 3493 functions for address manipulation mostly hide internal representations
from the casual and professional socket programmer.
Usage:
int connect(int sockfd, const struct sockaddr *peeraddr, int addrlen);
Usage:
int listen(int s, int backlog);
int accept(int s, struct sockaddr *addr, int *addrlen);
[1] Martin Duke, Robert T. Braden, Wesley Eddy, Ethan Blanton, and Alexander
Zimmermann.
A Roadmap for Transmission Control Protocol (TCP) Specification Documents.
RFC 7414, February 2015.