At the top of the file are some reasonably detailed

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: and such as telnet localhost 8090 and after the usual preamble about addresses and escape characters has appeared, try typing a line of text in to telnet and pressing return. You should see the same line of text reflected back to you, but in capital letters. Now have a look at the server.py code using your favourite text editor, and we’ll walk through what’s actually happened here. At the top of the file are some reasonably detailed comments on how the server implementation works; skip past these for now. Next you’ll see the usual ‘import’ section, which in this case uses ‘sys’ (python’s way of getting access to boring operating system functions such as ‘exit’ to cleanly quit a program or access the command line parameters), and ‘ex3’ (which is the module we’ve provided, and from which in this case we import the ‘Server’ functions). The next bit of the file does something we’ve not looked at in Python yet, and creates a Python class called EchoServer, which inherits its functionality from the Server class we’ve provided in ex3.py (this is pretty much the same as Java’s use of ‘extends’, it’s just that the syntax is different). As with our approach to Python in the rest of this course, the subtleties of the language’s object orientated model and class system are totally irrelevant here; and all that you need to know for this lab exercise should be quite clear from this simple example. If you look at the definition of the EchoServer class, you’ll see it contains two methods, onStart (which does nothing apart from print the welcome message), and onMessage (which you can see does very little apart from convert the incoming message in to upper case, and then ‘send it on a socket’ – we’ll look at what this means in a little more detail shortly). The file then contains an alternative server implementation called EgoServer; skip this for now and look at the last few lines starting from the comment # Parse the IP address and port you wish to listen on These last few lines of code simply take the command line arguments for ip address and port,...
View Full Document

This document was uploaded on 02/10/2014.

Ask a homework question - tutors are online