|
Learning Outcomes: At the end of this exercise the successful student have learned how to write client and server programs to handle streamed data. Exercise: This lab is about programming a simple streaming service and its control protocol. The client connects to the server and sends a PLAY message. The server then begins streaming data to the client (rather than send some audio or video we shall be sending a sequence of numbers). The client can ask the server to stop (or pause), rewind or end the stream (and close the connection) at any time. You can assume that there's only one client, but dealing with multiple clients is very easy. As well as requiring an application layer protocol this lab requires that you control various threads to manage the clients and server. Control of threads is a vital skill in communications programming. Note that the streamed data should typically be in a separate thread to control messages. Similarly the server's new connection socket should be in a separate thread to the the threads servicing various clients. On a more conceptual level, you should also be thinking about the issues involved with making a streaming service and the various design choices this involves. The Protocol: The protocol messages are:
No response messages from the server are required (initially, see below). Getting Started: First, download the given code. This is intended to give you a structure to work in, but you may modify and/or add to it as necessary, or ignore it altogether. There are five files:
Look at the TODO section (in comments) in each of these files for a description of the code which needs adding. Consider which of these requires threads and look at the server code for an example of handling threads. As ever, the Java API documentation should be checked for any unfamiliar classes. Extension: Implement response messages from the server. There are just two likely ones:
There are several ways this could be done, which require different modifications to the code. Think about the pros and cons to each approach. TCP vs UDP: Is TCP really the best protocol to use for this application? What are the advantages and disadvantages of each one? |