Simple Data Project

by: burt rosenberg
at: january 2019


It is all bits and bytes.

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 simplex-talk is the basis for this project. Migrate the networking code form simplex-talk into simple-data as needed. To understand this code, refer to Beej's Guide to Network Programming (thank you Brian Hall!).

Copy the [repo]/class/simple-talk folder to your folder [repo]/[user]/simplex-talk folder, compile and run. The makefile does a local run. Please read the makefile and code carefully and experiment by running the server and client on different machines in the lab.

To benefit from this code, as you migrate it, you must read it, grok it, even adore it

Finally, accomplish the task of this project. Copy the template files [repo]/[class]/proj1 to youre [repo]/[user]/proj1 folder, add and commit with message -m "initial commit". Work your changes, committing when you reach a subgoals (at least). Commit on the due date with the message -m "submitted for grading".

Man page

NAME
   simple-data-s, simple-data-c --- client/server pair to send a message
      
SYNOPSIS

    simple-data-s [-v] [-p port] [-l count]
    simple-data-c [-v] [-p port] host message

DESCRIPTION

   Server listens on the default port, or port given by the -p option, for a data 
   packet from the client. It prints out the message and number on separate lines and
   then repeats for count repetitions then exits. It repeats forever if count is 0,
   which is the default.
   
   Client sends a single data packet to the host at given host, with message and number
   according to the data format. Message is a text message of equal or less than 255
   bytes.
   
OPTIONS

    -l server is to receive count messages and exit. Default is 0, which means to loop forever
    -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
    and number on two separate lines. The message is printed between two pipe 
    characters ("|") and any non-printable characters are printed as a dot (".").
    [Added 1 Feb 2019: the number is the size of the received packet.]
    
HISTORY

    New for csc424-182.
    Simplified csc424-192 for just sending the message
    

Data format

You are to send by TCP a data packet of n+1 bytes, where n is the text message length. The first byte is n, the message size. Note that this means messages are at most 255 bytes long. The null termination byte is not sent among the characters.


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

The message need not be a string. In testing, it is hard to test a non-string message because command line arguments are necessarily strings. Students often error on their handling of the null string termination character. The string "hello" must be sent as exactly 5 characters, without the null termination character. To print the received message, the server code will put back the null terminator.

Testing

The default target does a localhost test. The Makefile understands prerequisites so first the default target (just typing "make") makes sure the dot-c's are compiled, and will compile them if they are not. Then it runs the server. Then it runs the client with hostname "localhost" and message "hello world". The server writes what it receives to the test.out file, which is then compared (using diff) to the test.ref file.

The clean target is then invoked to remove the build products and the test.out file.

"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 (which might have been Wifi if the packet really had to get someplace else).

A more fun test is to run the client and server on different machines, so the packet actually travels the Internet. To do this, start an AWS instance, connect to the instane, and note the IP address used in the connect string. Pull your repo onto the instance and then "make run-server".

On your local machine, pull the repo, edit the Makefile changing localhost to the IP address note above, and "make run-client".

Note that a custom security filter rule, allowing TCP port 5432 must be installed for the instance. Else the UPD packet gets dropped at Amazon's gateway.

How to use AWS

You can carry out this project using the lab, your own computer, or a combination. But in class I showed how to use Amazon AWS, and think that this is a good time for you to learn how to create an ECC instance (Elastic Cloud Computing).

To review the process:

  1. You will need to create an account at aws.amazon.com.
  2. Navigate in the AWS portal to the ECC service, and find the Create Instance button. It is around in a few places.
  3. You have choices of the AMI (Amazon Machine Image). Choose 64-bit Ubuntu, and choose always "Free Tier Eligible". For those recently signed up, then this ECC Instance will be mostly free. Else it is low cost.
  4. During the instance creation, you will be asked to create, or use and existing, private-public key pair. If you don't know what this means, create a new pair and download the dot-pem file that results. In a terminal window, "chmod go-rw" the pem-file else ssh will reject it.
  5. Once your instance is running, select it from the list of instances on the ECC management panel and select Connect. A pop-up will give you the exact ssh command with options to use. Cut and paste into a terminal, making sure the pem-file from the previous step is in the current directory in which the command is run.
  6. Adjusting the filter rules: ECC filters network connections. It is a bit hidden, how to open the editor for the rules. This was demonstrated in class. To add a rule, you must define the ports, service, or protocol being opened, and you can narrow the set of hosts that can send to the instance. Choose all hosts for this. In class we showed how to open ICMP, and how to open a particular TCP type port.
  7. Stop or terminate your instance when not experimenting. If you stop, your ECC instance is removed, but you Elastic Block Storage (EBS) stays. Restarting, you reconnect with the EBS and your permanent data is recovered. If you terminate, both the ECC and the EBS are removed.
  8. Educate yourself about the Free Tier. If you are a new AWS user, for 12 months you will have enough free credits for this course. If not, the free tier provides $12.00/month in service for free; but I suspect $6.00/month is sufficient for the course. Remember to terminate your instances when they are not in use, unless you want to retain the EBS to continue where you left off. Then use stop.
  9. Do terminate at the end of the semester to release the EBS as well.
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: 24 jan 2019