UDP/IP Sockets Demo 4
Demo 4: Sending messages and response messages
This sample program demonstrates how a client sends a bunch of messages to a server and how the server listens for them. The server loops on recvfrom, waiting for messages. When it gets a message, it prints it to the standard output, sends an acknowledgement message back to the sender, and waits for the next message.
To run this program,
download the demo file and unzip
it to create the demo-udp-04
directory.
If you are using a shared machine, you may want to change the port number defined in port.h
.
If you want to run the server on a different machine from the client, you will need to change
the IP address that is defined in the client (udp-send.c
).
Then compile the file
by running make
or manually with:
Then run the server in one window:
This is the server and you will see a message along the lines of:
Run the client in another window:
You should immediately see a stream of messages:
On the client, you should see messages indicating that packets were received: