-
Notifications
You must be signed in to change notification settings - Fork 2
Sockets
Sockets are a very general way for two (or more, depending on the type of socket) endpoints (code that generates or consumes data) to communicate with each other in both directions (as opposed to pipes, which are historically one-directional). We say "very general" because these two connections could be between endpoints within the same process, between endpoints on different processes on the same machine, or between endpoints on different processes on different machines (that are connected over some network, such as your local Wifi network or the Internet).
Generally, how sockets work is that each endpoint creates an object known as a socket that it will use to communicate with. Then, depending on the type of socket (more on that later), a series of steps is taken to make the socket "visible" to the outside world (this series of steps and the meaning of being "visible" depends on the nature of the socket and which end of the connection that given socket will taken on).
A socket is written to / read from an object known as a socket descriptor, which for all intents and purposes is the same as a file descriptor that you can write to and read from.
There are three types of sockets: TCP sockets, UDP sockets, and Unix Domain Sockets (or just Unix sockets). We now do a deep-dive into these three types of sockets which differ in substantial ways.
TCP (Transmission Control Protocol
The socket API is complex and has a lot of subtleties.
socket
connect
accept
listen
bind
sendto
recvfrom
ip_addr
htons
htonl
net_handler
executor
net_handler_client
dev_handler_client
- Important
- Advanced/Specific