The code to work with sockets has a lot of details. They are found in Beej's Guide to Network programming and presented on my Netbounce page.
Much of the details can be hidden by a software layer, as long as the layer's API is well designed for the requirements. This project is about using a layer, called Foo Sockets, for UDP programming. Hopefully it communicates the essentials of programming with packet-style communication.
As a fun thing, we will learn more about the common technologies about the web. In the project we install a Netbounce Responder in an EC2 instance and direct its output to a webpage. We need to configure our webserver to use Server Side Includes (SSI), a form of server-side scripting. It will also be useful for our next program as we try to monitor the progress of UDP packets we try to bounce from machine to machine.
To create the Netbounce Responder carry out the tasks found on the Netbounce Responder page.
The responder uses the code from the Netbounce page. However the server has a version that uses foo-sockets. As you attempt to write a version of the client that uses foo-sockets, refer to this code for inspiration and help.
NAME
netbounce-server2, netbounce-client2
SYNOPSIS
netbounce-client2 [-v] -p port -h host message
netbounce-server2 [-vl] -p port
DESCRIPTION
netbounce-server2 binds to the given UDP port, listens for a packet
and echos it back to the source port and source IP.
netbounce-client2 sends the given message in a UDP packet to the given
port and host, then listens for a packet on the port that its
socket was bound to. It prints out the contents of the returned
packet to stdout.
The verbose option (-v) prints to stdout. Multiple -v increase
the verbose level.
The loop option (-l) will have the server listen repeated on the port.
Else it exits after one bounce.
BUGS
LAST UPDATE
01 February 2026
20 January 2012
12 January 2016
NAME
create_foo_socket, socket_sendto, socket_recvfrom,
socket_replyto, create_session_socket
SYNOPSIS
#include "foo-socket.h"
struct FooSocket *
create_foo_socket(int port) ;
int
socket_sendto(struct FooSocket * foo_sock, char * host, int port, char * message, int msg_len) ;
int
socket_recvfrom( struct FooSocket * foo_sock, char * buf, int buf_len) ;
int
socket_replyto(struct FooSocket * foo_sock, char * message, int buf_len) ;
struct FooSocket *
create_session_socket(struct FooSocket * sock_listen) ;
DESCRIPTION
The create_foo_socket returns a struct FooSocket * representing a newly
opened socket. If a non-zero port is given, the socket is bound to that port.
Else the socket is bound to an ephemeral port.
The socket_sendto sends the message on the foo_socket to host:port.
The socket_recvfrom receives into buf from the foo_socket up to buf_len bytes,
returning the number of bytes received. The foo_socket binds to the packet
source for the purpose of socket_replyto.
The socket_replyto sends the message in reply to the sender of the previous
socket_recv_from.
The create_session_socket returns a new foo_socket, a clone of the foo_sock
bound to a sender after a socket_recvfrom.
BUGS
LAST UPDATE
01 February 2026
There are general rules in the use of the foo socket calls.
Then send requires the full target address: the IP address and the port number. The foo socket layer takes care of the details for filling out the struct sockaddr_in addr address structure.
The receives blocks on listening for a packet delivered to the port number of the socket.
Foo Sockets facilitates this scenario by the server calling create_session_socket and replying on that foo socket. After the initiating socket_sendto the client sends further messages with socket_replyto, having captured the new port number.

author: burton rosenberg
created: 8 feb 2024
update: 3 feb 2026