6.7

Week 6 Set a

home work!

Programming Language BSL+

Due Date Mon at 9pm (Week 6)

Purpose To use a list-based data representation of information in a real-world setting, namely, the communication between your chat client and the server

Finger Exercises

None

Graded Exercises

Exercise 1 Problem 2 of Week 5 Set a requested a revision of the data representation of conversations to use lists. Before proceeding, fix your solution in response to our feedback.

In the meantime, we have switched the server so it uses lists as messages.Encoding commands as strings (see the "-ben" example) as Week 3 Set c does, is a horrible idea. Only uneducated developers make such choices when structured data is available. Ideally, the server should use structures instead of lists, but the creator of the universe teachpack included the wrong kind of structures :-(. Specifically, the server now accepts Commands:

; A Command is one of:

   

interpretation

; -- String

   

plain message

; -- (list "COLOR" String)

   

color command

; -- (list "BLACKLIST" String)

   

blacklist command

The server interprets these commands plus connection and disconnection events as follows:

When a client C ...

the server ...

connect,

broadcasts a join message for C

sends (list "COLOR" cs),

sets C’s color to cs

sends a String s,

broadcasts an ordinary message from C

 

with s split into words plus a color string cs

 

... using "black" as the default for cs

 

... or the color set by C most recently

sends (list "BLACKLIST" n),

blocks n from sending messages to C

disconnects,

broadcasts an exit message for C.

The representation of names follows the convention of Client Programs.

What this means for your client

These changes have consequences the messages your client receives and the commands it sends. Your task is to adapt your client to this revised server.

Sending Commands Your client must send Commands to the server. What it sends, depends on what the user types into the text field. Here is one example:

When the user types ...

your client sends ...

"-abc"

(list "BLACKLIST" "abc")

You will have to develop such conventions for all the Commands that the client must be able to send to the server. We leave it to you what these conventions are, but you must write them down as a part of the file’s purpose statement.

Receiving Messages Your client will now receive Chats not just strings:

; A Chat is one of:

   

interpretation

; -- (list "MSG" String List-of-strings String)

   

ordinary message

; -- (list "JOIN" String)

   

join message

; -- (list "EXIT" String)

   

exit message

Your client still adds each of these messages to the conversation (history) as the most recent addition. It interprets Chats for to-draw as follows:

When the server sends

the client renders it as a text image of ...

(list "MSG" p m cs),

the list of words m in color cs

 

... indicating that it originated from p.

(list "JOIN" p),

p that tells the user about the new participant.

(list "EXIT" p),

p that tells the user about the

 

... departure of the participant.

In addition to the above, the client may also receive an error Chat:

; A Chat is one of:

   

interpretation

. . .

   

. . .

; -- (list "ERROR" String)

   

error message

An Browsers and apps receive such messages, too. How do they deal with it? error message informs you that the client sent a bad message to the server. Deal with it in any way you want.

Running the code in your definitions window may not open a big-bang window.