CS61A Lab 13: Client/Server Programming

Week 13, 2011


We have written a nice little client-server set of programs for doing instant messaging! You can find the code in the following 4 files:

To run the chat program, first start the server program on a computer:

# python3 chatserver.py

This will ask you to find out your IP address and will tell you the port the server is using (it's randomly selected every time the server starts).

Note: If you're doing this from home, you're probably connected to a local router, in which case it won't work unless you're doing "port forwarding" (if you don't know what this is, don't worry about it). To handle this, log onto one of the school servers and use the server's full name (eg. star.cs.berkeley.edu) for the IP address when connecting the client.

Then start a client!

# python3 chatclient.py

This will ask you for a username, the server's address, and the server's port. Afterwards you can use /help to see all of the possible commands for the client. After logging on, you will receive any messages that others have sent you after each command (so you have to hit enter to receive new messages).

Question 0

Both the client and the server use the Message class to send messages to each other. A Message has four components:

Take a look at the code and list all the kinds of message actions that a Message sent from either the client or server can have. Who sends what types of messages?

Question 1

Modify the server program to understand a new type of message, which will have action broadcast. The server program should handle messages with action broadcast by sending the message on to all clients it has connected to it.

Once you have modified the server, add a new /broadcast [message] command to the client, which sends a broadcast message to the server.

Question 2

Modify the client program to have a blocked users list. The client should not see any messages from anyone on their blocked users list! Add three new commands for the client: