On this page:
In the Beginning...
How it Works
Clients
Running the Client
I’m gonna wreck it
spam spam spam spam spammity spam
6.7

Lab 10 Chat Client

home work!

Purpose: In this lab, you’ll use Racket’s universe to improve a chat client that works with a server on another machine. You also get practice working with code written by others — including code that is insufficiently tested, like this code written by your time-strapped TA.

In the Beginning...

Your TAs were originally thinking about slowly walking you through writing a super complex chat program. Unfortunately all the TAs are overworked undergrads and your Professor is teaching far too many classes. So the TA assigned to writing this lab quickly threw together some code that works... most of the time.

In the hopes of having better code for next year’s students you have all been recruited as Quality Assurance testers and bug fixers.

In this lab each pair will work on two computers. To start, you will need to download the chat client and chat server on to each computer. (Right click and save target.)

How it Works

The Universe teachpack allows for client/server programs — that is, programs where a server manages multiple clients, and a client and the server communicate through Messages.

To start our client, we use the big-bang form that we’ve been using all semester, while the server is started using a new universe form. A longer description of client/server programming can be found on the main Universe HelpDesk page.

Clients

Client programs look very similar to the kinds of interactive programs we’ve already written. There are just a few changes involved:
  • A name clause to identify the client,

  • A register clause to connect to a server, and

  • New protocols for sending (Packages) and receiving (Messages) to/from the server.

Connecting to the Server

To connect we use the clause (register String), where the String is either a hostname or an IP address. The hostname for each computer in the lab should be "<machine-name>.ccs.neu.edu", where "<machine-name>" is the name printed on a label on the side of the computer. When big-bang is executed, it attempts to connect to the universe running on the given machine. If the connection fails the program (i.e., the client) will run locally without sending Messages.

In addition, a client should specify a name using (name String) to identify it to other clients. In our chat program, we will use it as the nickname of each connected user.

Sending Messages to the server

To send Messages to the server, functions that originally returned a new World can instead (optionally) return a package. For example, the on-key clause originally took a function with the following contract:

; World KeyEvent -> World

But now we’ll treat it as:

; World KeyEvent -> [Or World Package]
 
; An [Or X Y] is one of:
;  - X
;  - Y

A Package consists of two items: a new World (as before) and a Message to send to the server.

; A Package is: (make-package World Message)
 
; A Message is a SExpr
 
; An Atom is one of:
; - Number
; - Symbol
; - String
 
; An SExpr is one of:
; - Atom
; - [List-of SExpr]

Running the Client

First things first... your name’s not Alfred E. Neuman right? Modify your nick to something reasonable (keep it at most PG-13, please). Now look through the code, and try to get an idea of what it does.

Now that you have a background on the World, Universe, and the client code, we can start working.

Run Chat Server on one of the computers. Then run one copy of Chat Client on each computer (make sure to swap out your nickname and the hostname/ip address).

Now you should be able to chat between the two servers. If you send a message "/color" followed by a number 0-8 your font color will change. Send a couple messages to make sure everything is working.

I’m gonna wreck it

The code seems reasonably functional, although you may have noticed a horrible lack of tests. Appearances are deceiving: this code isn’t robust at all. When you start writing code that has to interact with other people’s code you realize not everyone follows the directions. The client we provided you only works in “ideal” cases and crashes when anything goes wrong.

Exercise 1 Without modifying the server code try to make your partner’s client crash. Note, because of the way the server sends message this may cause your own client to crash so modify your client so it can survive sending the message.

Exercise 2 When your partner manages to crash your client find a way to fix your client so that that message no longer causes a crash.

Repeat (keep notes of what you have found and fixed).

spam spam spam spam spammity spam

Eventually you run out of ways to break your partner’s client and just decide to annoy the heck out of them.

Exercise 3 Write a spambot that given a [List-of String] sends one line at a time to the server.

(define STILL-ALIVE
  (list "This was a triumph."
        "I'm making a note here:"
        "HUGE SUCCESS."
        "It's hard to overstate my satisfaction."
        "..."
        "Aperture Science."
        "We do what we must because we can."
        "For the good of all of us"
        "Except the ones who are dead."
        "..."
        "But there's no sense crying over every mistake."
        "You just keep on trying till you run out of cake."
        "And the science gets done and you make a neat gun."
        "For the people who are still alive."
        "..."
        "I'm not even angry."
        "I'm being so sincere right now."
        "Even though you broke my heart and killed me."
        "And tore me to pieces."
        "And threw every piece into a fire."
        "As they burned it hurt because"
        "I was so happy for you!"
        "..."
        "Now these points of data make a beautiful line."
        "And we're out of beta, we're releasing on time."
        "So I'm GLaD I got burned."
        "Think of all the things we learned"
        "For the people who are still alive."
        "..."
        "Go ahead and leave me."
        "I think I prefer to stay inside."
        "Maybe you'll find someone else to help you."
        "Maybe Black Mesa..."
        "THAT WAS A JOKE. Haha. FAT CHANCE."
        "Anyway, this cake is great."
        "It's so delicious and moist."
        "..."
        "Look at me still talking when there's science to do."
        "When I look out there it makes me GLaD I'm not you."
        "I've experiments to run there is research to be done"
        "On the people who are still alive"
        "..."
        "And believe me I am still alive."
        "I'm doing science and I'm still alive."
        "I feel FANTASTIC and I'm still alive."
        "While you're dying I'll be still alive."
        "And when you're dead I will be still alive."
        "..."
        "Still alive"
        "Still alive"))

Exercise 4 Try modifying the server so it won’t allow invalid messages, instead of passing on bad messages.