Sender Program (sender.c):

The sender program is a UDP datagram sender that can be configured through command line options. It initializes Winsock, creates a UDP socket, and either connects to a recipient’s IP address or uses sendto() to send datagram messages. The program allows customization of parameters such as the remote port, recipient’s IP address, message count, buffer size, and the character used to fill the buffer.

Compile:

cl -o Sender Sender.c ws2_32.lib

Command line options:

sender [-p:int] [-r:IP] [-c] [-n:x] [-b:x] [-d:c]
-p:int Remote port
-r:IP Recipient’s IP address or hostname
-c Connect to remote IP first
-n:x Number of times to send message
-b:x Size of buffer to send
-d:c Character to fill buffer with

Receiver Program (receiver.c):

The receiver program complements the sender by receiving UDP datagrams. It initializes Winsock, creates a UDP socket, binds to a specified local IP and port, and enters a loop to continuously receive datagram messages using recvfrom(). The program supports command line options for configuring the local port, local IP address, and buffer size. Received data can be processed within the loop, making it suitable for handling incoming UDP messages.

Compile:

cl -o Receiver Receiver.c ws2_32.lib

Command line options:

sender [-p:int] [-i:IP][-n:x] [-b:x]
-p:int Local port
-i:IP Local IP address to listen on
-n:x Number of times to send message
-b:x Size of buffer to send

Here is a basic example of a receiver.c program that complements the sender.c program. This receiver program binds to the specified interface and port number and then blocks on a recvfrom() call to receive UDP datagrams: