{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Here are some handy bits of python that you might

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e this a chat system that works for exactly two users at a time; not one, not three, but exactly and only two. We’ll also assume that each user can type exactly one message, and then has to wait for the other user to reply before they can enter another message. At this point, move away from your keyboard and think for a while. The actual code you are going to write is very simple, with the module we’ve given you doing all the messy stuff for you. What’s needed is for you to come up with a sensible strategy (a ‘protocol’) that will allow two independent programs to exchange messages using only the functionality provided by your simple server. Here are some hints to get you going. The basic functionality is EXTREMELY simple. Almost trivial, roughly along the lines of: 1. Wait for the user to type in a message 2. Send that message to the server 3. Wait for there to be a reply from the other user 4. Fetch and display the reply 5. Go back to step 1 But there is at least one important thing to consider: Obviously, if both users are waiting to send or receive a message at the same time, our system is instantly deadlocked and nothing will work. You’ll need to think of some way of starting one user off in the ‘sending a message’ state, and the other user off in the ‘waiting for a message’ state. There are lots of ways of doing this, some more elegant than others. Here are some handy bits of python that you might need to use To get a line of input from the user, use something like myMessage = raw_input(’Type your message: ’) (we’ve used this in the examples class notes, and in the previous lab) To ‘wait a while’, import the ‘time’ module (‘import time’) and use time.sleep(numberOfSeconds) You might want to think about what happens if your program crashes mid chat. Do...
View Full Document

{[ snackBarMessage ]}