6.6

Assignment 9

home work!

Programming Language ISL

Due Date Thursday 10/18 at 9pm

Purpose To practice iterative refinement and list-processing, as well as learning about universe and distributed programming.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions.

  • You must submit with your old homework partner. The new homework partner given in lab this past Tuesday is for assignment 10 and onward.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • All steps of the design recipe are required.

Project (Part 2)

Recall that in part 1 we asked you to design a music player that would switch between two songs. We want to extend that music player to allow you to connect to a server, which will provide the songs you can play.

The first thing your program will do is register with the server using the register clause. This clause takes the name of the server you are trying to connect to. To connect to our server you must provide it with the string "dictionary.ccs.neu.edu".

We have several servers running concurrently, so your program will also have to specify which port to connect to using the port clause. You should connect to port 10001.

Your program will have to communicate with the server to let it know when you need a new song to play. You can do this by sending the message "next" in a package. A Package is a structure that takes the next state of your world, and the message to send to the server. Any of your handler functions that return a MusicPlayer (the function for on-tick, the function for on-key, or the function for on-mouse) can produce a Package instead.

; A Package is a (make-package MusicPlayer ClientMsg)
; - and dictates the next state of the world as well as
; - the message sent from the client to the server
 
; A ClientMsg is "next"
; and represents a request for the next song

You may notice that we have not provided the structure definition for a package structure. You should only ever need to CREATE a Package. You should never need to pull it apart. Therefore you should not attempt to write a template for the Package data definition. When writing examples of Packages remember that "next" is the only valid message you can send to the server. You do also not need to write a template for a client message as it is a trivial template.

Of course, the server will need a way to send you a response. The response will have to include the actual byte-string containing the song’s music as well as some meta-data (such as the name of the song). We also need a way for the server to tell us if we have done something wrong.

; A ServerMsg is one of:
; - ErrorMsg
; - SongMsg
 
; An ErrorMsg is a (list "ERROR" String)
; where the second string is the message from the server about what went wrong
 
; A SongMsg is a (list "SONG" Metadata String)
; - where the metadata is information about the given song
; - and the second the String is the actual byte-string of music
 
; A Metadata is a (list String String Number String)
; - where the first String is the song's title
; - the second String is the song's artist
; - the Number is the length of the song (in seconds)
; - and the third String is the song's album

To handle messages from the server we will have to add yet another clause: on-receive. This clause tells us what the next state of the world will be after receiving a message from the server. The on-receive clause takes a function with the following signature:

; MusicPlayer ServerMsg -> PlayerResult
 
; A PlayerResult is one of:
; - MusicPlayer
; - Package

Exercise 1 If you still have questions about how your program interacts with the server, read "The World Is Not Enough" to see the documentation and an example of how it all comes together. Of course, the course staff will also be available to answer any questions you may have.

Exercise 2 Edit your data definition for a MusicPlayer. Remember that there are now three different stages of your program: (1) You have just started the program, (2) you have requested a song but have not yet received one, and (3) you have received a song from the server. Your program will only have to keep track of one song at a time, but you wil have to find a way to keep track of any other information at each stage.

Exercise 3 Design your world program. Your program should request a new song from the server whenever it is not waiting for a song or does not currently have a song to play. Once you have a song, you should be able to play it by pressing the spacebar. The music player should display the name of the next song you will play (if there is one), the artist for that song, and the feedback from the previous song you played (if there was one). You may choose to display more information about the song (e.g. the album or the length of the song) but it is not necessary.

Hint: It is recommended (but not required) that you convert any SongMsg you receive from the Server into a structure of some kind. This will make it easier to work with the data.