a socket and the BSD socket API
/ BSD -> BEE-ESS-DEE, socket -> SOCK-it /
Think of a socket as the wall outlet your program plugs into to reach the network. Once it is plugged in, your code does not deal with cables, routers, or IP packets directly - it just reads bytes coming in and writes bytes going out through that one outlet. A socket is the operating system's handle for one end of a network conversation: an endpoint your program owns and uses to send and receive.
Concretely, a socket is created by a system call and comes back as a file descriptor - the same kind of small integer the OS gives you for an open file. That is deliberate: the designers made the network look like a file so you could read() and write() it with calls you already know. The BSD socket API (born in Berkeley Unix in the early 1980s) is the small set of system calls that create and operate these endpoints: socket(), bind(), listen(), accept(), connect(), send(), recv(), close(), and a few helpers. Almost every operating system - Linux, macOS, Windows (as Winsock) - offers nearly the same calls, which is why socket code is so portable.
Why it matters: the socket is where your program meets the network, and the BSD API is the universal vocabulary for that meeting. Learn these handful of calls and you can write both clients and servers on essentially any machine. The key mental shift is that a socket is just a file descriptor with a network on the other end - so all your hard-won knowledge about file descriptors, blocking, and partial reads applies directly here.
int fd = socket(AF_INET, SOCK_STREAM, 0); creates a TCP socket. The return value fd is a file descriptor, perhaps 3 - from here on you can read(fd, ...), write(fd, ...), or the network-specific recv(fd, ...) and send(fd, ...) on it, and close(fd) when done.
socket() returns a file descriptor; the network is now just another thing you read and write.
A socket is a kernel object referenced by a file descriptor, not a piece of hardware and not the same as a port. One process can hold many sockets at once, just as it can hold many open files.