//
A Socket is an endpoint for sending and receiving data across a computer network. It is the fundamental abstraction that allows application-level programs (web servers, chat clients, games) to communicate over TCP/IP.
A socket is uniquely identified by: (IP Address, Port Number, Protocol). When a web server runs on 192.168.1.10:80 using TCP, that specific combination is a socket.
socket(): Create a socket object.bind(): Bind the socket to a specific IP address and port number.listen(): Put the socket in listening mode, ready to accept connections.accept(): Block and wait. When a client connects, accept returns a NEW socket dedicated to that client.recv() / send(): Exchange data with the client.close(): Close the connection.socket(): Create a socket.connect(): Connect to the server's IP and port (triggers the TCP 3-way handshake).send() / recv(): Exchange data.close(): Close the connection.No connection is established. The client simply sends datagrams to a destination address.
recvfrom() and sendto().sendto() and recvfrom().connect(), listen(), or accept() needed.A simple single-threaded server can only handle one client at a time. To handle thousands of concurrent clients:
select(), poll(), or epoll() to monitor multiple sockets on a single thread. Node.js uses this model.