Overview
In this assignment, you will be required to implement client and server programs for a shared white board application. The application requires two components to be implemented, the client and the server. The client allows a user to manually input drawing commands, which is send to the server. The server then takes these messages and sends them to all of the other clients connected to it. The end result is that all clients can see the drawings being entered by the other users, and the server provides the ability to connect them all together.
Program Requirements
You are required to implement a client in Java as a console based application, which is capable of taking inputs from the user and sending them across the network. Messages from the network must be displayed as text on the standard output device. The server must also be implemented in Java, as a simple console based application. You are free to implement your Java code for the client and server in any way that you like, as long as it meets the following guidelines:
It must run on Cis-lab using only standard JDK classes and no other external classes
The server should not have any user interface but may print out text debugging
You must use the network protocol and ports that we have specified in this document
You must use the supplied command lines to start up your client and server
This assignment is broken up into two parts, the client and the server. We will provide a server that implements the protocol specified in this document which you can use to test your client against while you are developing it. The provided server will also be useful to allow you to test your assignment with other students who are testing at the same time. When your client is working, you can then use it to test out the server that you have implemented yourself.
Network Protocol
The protocol that is used in this assignment is based on a simple text format to make it easy to implement and debug and problems. Messages are sent over a TCP connection to guarantee reliability and delivery, and also to provide a simple transmission mechanism similar to writing to a file. Each message is sent as a command followed by the required arguments, using a single space character as a separator and a new line character to end the command. Note that the client can exit by simply closing the connection to the server, and the server must handle this cleanly. There are a set of protocol messages that you will be required to implement.
Client to server messages
LOGIN [username]
The client sends this message to the server when it initially connects. The server will not process any other messages nor allow the client to see any drawing messages until this message has been processed. The username must contain only the letters A-Z, a-z, or the digits 0-9, any other characters such as punctuation or spaces are not allowed. The server must check to ensure that usernames are unique, so that no two clients may connect with the same user name.#p#分页标题#e#
DRAW [x1] [y1] [x2] [y2] [colourname]
Server to client messages
WELCOME [any other data may go here]
This message is sent by the server when a new client connects to it. The welcome message may contain a string containing any number of characters including spaces. You may put whatever
welcome message you would like clients to see, and would typically include your name and any other descriptive text. The client must display this text so the user knows what server they have connected to.
LOGIN_OK
This message is sent by the server when it has received the LOGIN command from the client. It indicates that the server is now ready to accept DRAW commands from the client, and will pass on messages from other clients.
DRAWMSG [username] [x1] [y1] [x2] [y2] [colourname]
This message is sent by the server whenever a client sends a DRAW message to it. The server is responsible for working out the username of the client connected to it that generated the DRAW message, and then generating a new message which is sent to all of the clients. Note that this message is sent to all of the clients, including the client that generated it. The coordinates and colours are specified in the same way as the previous DRAW message.
ERROR [reason string]
If the server does not understand a message that the client sent to it, the server should generate an error message so that the client can print this out for debugging. This will be useful as you test your client and server against those written by others. The reason string must be a single line of text and can contain any characters including spaces - it should be descriptive enough so that the remote client programmer knows what their program has done wrong. Some example messages could be:
ERROR Cannot accept DRAW command until after LOGIN request ERROR DRAW command contains a value which is out of bounds ERROR The supplied username is already in use
After generating an ERROR message, the server should close the connection and not try to continue processing because there is an error in the protocol implementation (probably caused by the client, although this is assuming the server does not have any bugs in the code). Note that if the server fails then it may simply close the connection without any response, and the client should then terminate with an error message.
Protocol ordering
When a client connects to the server, messages will be sent back and forth in the following order. Any other order is not supported. Note that the server is not required to store drawing commands internally, so if a client joins the server later than other clients, it will miss out on any lines drawn beforehand. An ERROR message may occur at any time and after this the server automatically closes the connection. The startup sequence is as follows:
Command Line Arguments
Both the client and server will be controlled via command line arguments on start up. For the client, you will need to specify the Internet host name that the server is running on, the TCP port number to connect to, and the username to use. For the server, you will need to specify the port number to listen for incoming connections on. If other users are on the system you will need to pick a port number that is not currently in use. When we mark your assignment we will make sure that we use a port number which is available for use.#p#分页标题#e#
For the client, the command line syntax must be:
java Client [hostname] [port] [username]
For the server, the command line syntax must be:
java Server [port]
Hostname is any acceptable Internet machine name: either a machine name, a fully qualified domain name, or an IP address. The port number is a single integer value, and will be above 1024 since only these are available for user applications. The username must be in a format which is suitable for transmission using the protocol described earlier.
It is expected that you will check all command line arguments to ensure they are valid and generate a suitable error message if they are not correct.
www.ukthesis.org整理提供
相关文章
UKthesis provides an online writing service for all types of academic writing. Check out some of them and don't hesitate to place your order.