TCP/IP is the foundation of internet communication, and sockets provide a way for programs to send and receive data over the network. This tutorial introduces how the TCP/IP model works and how sockets are used in network programming.
TCP/IP is a suite of protocols that defines how data is transmitted across networks. It consists of layers:
A socket is an endpoint for sending or receiving data between two machines. It’s defined by:
Example of a socket: 192.168.1.10:8080
int sock = socket(AF_INET, SOCK_STREAM, 0);
connect(sock, server_address);
send(sock, "Hello", 5, 0);
recv(sock, buffer, sizeof(buffer), 0);
A basic TCP server:
80
: HTTP443
: HTTPS22
: SSH53
: DNSnetstat
: View active connectionsss
: Socket statisticstelnet
or nc
: Test open portsTry writing a simple chat application using sockets. Understanding TCP/IP and sockets is key to systems programming, web development, and cybersecurity.