UDP/IP Sockets Demo 3
Demo 3: Sending messages from a client to a server
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 and waits for the next message.
To run this program,
download the demo file and unzip
it to create the demo-udp-03
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 server, you should see messages indicating that packets were received: