Making a basic TCP IPv4 POSIX socket

Getting started

We suppose the server and client are on LAN.

On server

  1. Search your local IP
ip address show
  1. Compile
make server
  1. On listening. [PORT] must replace to an available port. We recommend PORT=8080. But, port 7 is commonly used to echo sockets.
./server.out [PORT]
Server demo

On client

  1. Compile
make client
  1. The client connects to the server.
./client.out <SERVER ADDRESS IPv4> <ECHO WORD> [<SERVER PORT>]
The client sends a message to the server.

The server receives the client's message

Server receives message

Peer-to-peer socket magic

Spork CLI tool. (2022, September 27). Retrieved from https://spork.sh

Code

sanchezcarlosjr. (2022, September 26). operating-systems. Retrieved from https://github.com/sanchezcarlosjr/operating-systems/tree/main/posix_basic_tcp_ipv4_sockets

References