the dev/random device

Simple Data Project

by: burt rosenberg
at: february 2021

Overview

This project has three goals:

  1. To familiarize class participant with the tools of the course.
  2. To teach by example socket/stream coding (crash course).
  3. To exercise data representation for network communications.

The code of netbounce is the basis for this project. To understand this code, refer to Beej's Guide to Network Programming.

New proj2 templates released Thursday; please update.

Man page

NAME
   simple-datagram --- client/server pair to send a message
      
SYNOPSIS

    simple-datagram [-v] [-p port]
    simple-datagram [-v] [-p port] host

DESCRIPTION

   Invoked with host program is a UDP client, sending message from standard in
   to host, then exits. Invoked without those arguments, program is a UDP server, listening
   for the message and prints it to standard out the exits.
 
OPTIONS

    -p port for client to send to, server to listen on. Default is port 5432.
    -v verbose
     
ARGUMENTS

    Host, the name of the host the client will send the data packet to.
    Message, a 255 or fewer byte text message

OUTPUT
  
    Without verbose options, server is silent except for printing each message.
    
HISTORY

    New for csc424-182.
    Simplified csc424-192 for just sending the message.
    Added 1 Feb 2019: the number is the size of the received packet.
    csc424-212: UDP protocol used.
    

Data format

You are to send by UDP a data packet of n+1 bytes, where n is the text message length. The first byte is n, the message size. In general, do not send the null termination byte of the string. The message "hello" will be 5 bytes, not six.


  0   1 2  ... n   
+-----------------+
|len|    message  |
+-----------------+

Copy the [repo]/class/proj2 folder to your [repo]/[user]/proj2 folder, and make an initial commit. The simple-datagram.c file is the template you are to work from. The Makefile includes a basic test. While you can initially work on a single EC2 instance, using the hostname localhost, all tests will be run separate EC2 instances for client and server.

Localhost is the IP address 127.0.0.1; and it refers to the machine itself. Message to and from localhost go through the socket and layer 4 (TCP/UDP), layer 3 (IP), but are just sent as a local memory copy for layer 2. It is also called the loopback address, and can be name lo in the output of the ifconfig command.

Testing:

Make sure your code works on both text and binary data. Students often confuse these two types of data.

Text: These are data bytes from text files. They are in the restricted range of printable characters. The never ever have a data byte of value zero. And the tend to be arranged in lines of data, terminated by an End Of Line character, or character pair, that is platform dependent.

Binary: This a a sequence of arbitrary bytes, each being from to take on the values 0 through 255. There is no structure other than the sequencing. That is they are not arranged in lines, and the data does not describe its own length.

AWS Hackery

Working on a single EC2 instance using two ssh connections and the localhost IP as the network address.

Once working, create separate EC2 instances for client and server. It is best you give the instances names, because this gets confusing. In order to communicate between hosts, the Inbound Rules for the attached Security Group need to be maintained. It is best to give the Security Group a name, and attached the same Security Group to both EC2 instances (for simplicity).

By default, the security group will have an entry for ssh — else you could not ssh into the instance. You can create an all-allowed pass for instances in the same security group by adding an inbound rule for "All UDP" with Source the security group.

Important! You will need to use the Private IPv4 address when invoking simple-datagram if you want the "All UDP" rule to apply. Private addresses only make sence within a single VPC (Virtual Private Cloud), a network that is walled off by the security group from all other networks.

EC2 instances are also assigned public IP addresses. These are used to connect to the instance from outside of the VPC. For instance, this address is used to ssh into your instances. Note that the security group for the public address will be much more restrictive. Generally access from the public address is allowed on a need-to-know basis.

For the convenience of our CSC 424 experiments, we are allowing all access when the instances are already safely sequestered in our own VPC.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

author: burton rosenberg
created: 25 jan 2018
update: 9 feb 2021