This project consists of a UDP ping client and server written in C++.
The client sends UDP packets to the server, which echoes them back.
Useful for measuring round-trip time (RTT) and network diagnostics.
- g++ (GNU C++ compiler)
- Make
-
Run the following command to compile both the client and the server:
make
-
To clean up object files and binaries:
make clean
The server listens for incoming UDP packets and echoes them back to the sender.
./udp-ping-server [-p port] [-a subnet]
-p <port>
– (Optional) Port to listen on. Default is 7777.-a <subnet>
– (Optional) Allow packets from specific subnets.- Can be used multiple times to add multiple subnets.
- If no subnet is specified, all IPs are allowed.
- Start the server on the default port (7777) and allow all IPs:
./udp-ping-server
- Start the server on port 9000, allowing packets from
192.168.1.x
and10.0.0.x
:./udp-ping-server -p 9000 -a 192.168.1. -a 10.0.0.
The client sends UDP packets to the server and calculates the round-trip time (RTT).
./udp-ping-client <server_ip_or_hostname> [-i interval] [-c count] [-d duration] [-s payload_size]
-p <port>
– (Optional) Port. Default is 7777.-i <interval>
– (Optional) Interval between packets in seconds (supports fractions, e.g.,0.05
). Default is 1 second.-c <count>
– (Optional) Number of packets to send. Default is infinite.-d <duration>
– (Optional) Stop after a specified duration (in seconds).-s <payload_size>
– (Optional) Size of the payload in bytes. Default is 64 bytes.
- Send packets to
192.168.0.10
every second, indefinitely:./udp-ping-client 192.168.0.10
- Send packets every 50 ms for 30 seconds:
./udp-ping-client 192.168.0.10 -i 0.05 -d 30
- Send 100 packets with 512-byte payloads:
./udp-ping-client 192.168.0.10 -c 100 -s 512
- The client sends UDP packets containing a sequence number and timestamp.
- The server echoes the packets back.
- The client calculates round-trip time (RTT) for each packet and prints the result.
- High latency and packet loss are reported in the statistics.
Response - seq: 1, rtt: 16.35 ms
Response - seq: 2, rtt: 32.50 ms [HIGH LATENCY]
Response - seq: 3, rtt: 15.28 ms
- Performance Optimization: Logging for accepted packets is disabled to improve server performance.
- Only rejected packets from unauthorized IPs are logged.