On this page:
Readings
Supplemental Materials
Pre-lecture
Goals
In-class
Homework

Module 08

Last updated: Wed, 4 Mar 2015 17:34:27 -0500

Readings
Supplemental Materials
Pre-lecture
  1. Read the Readings and Supplemental Materials.

Goals
In-class

The goal of this week’s in-class exercise is to make sure you understand how to connect to a Universe server.
A Universe client connects to a server using big-bang. The key difference is that the handler functions, e.g. next-world, key-handler, now produce a HandlerResult. A HandlerResult is defined:
; A HandlerResult is one of:
; - World
; - (make-package World MsgToServer)
A handler function produces a make-package in order to send messages to a server.
To receive messages from a Universe server, a Universe client must implement an on-receive handler, for example:

; receive : World MsgFromServer -> HandlerResult

A Universe client implementer designs the World data definition, as before.
However the data definitions MsgToServer and MsgFromServer constitute a protocol that the server and client must agree on. The design of protocols is similar to Data Design in many ways. For example, a poorly designed protocol may lead to server and client code that is more complicated than necessary.
However, designing protocols is outside the scope of this course so we will give you the protocol here and in this week’s homework, though you should make note of how the design of the protocol affects your code.
For the in-class exercise, both MsgToServer and MsgFromServer are Strings. Your World data definition can be whatever you wish, as usual.
The goal of the in-class exercise is to connect to the server and successfully receive and send the server a message. Specifically, when you successfully connect to the server, you’ll receive a first secret message.
Your client must implement an on-key handler such that if the space bar is pressed, the client sends the first secret message back to the server, at which time your client will receive a second secret message.
Your client should display the last received message from the server at all times.
Once you have sucessfully connected and sent and received the secret messages from the server, you’re done. Enjoy Spring Break! The status for each student will be displayed on the screen at the front of the class.
To help you get started, use the following function to connect to the server. The specific server IP will be determined during class.
; A UserName is a String, consisting of letters and numbers
 
; run : UserName -> World
; Connect to the given server with user name n.
(define (run n server)
  (big-bang INITIAL-WORLD
            (on-receive receive)
            (on-draw render)
            (on-key key-handler)
            (name n)
            (register server)
            (port 5009)))

Homework

Problem Set 08