Some of these questions will be must be handed in for assessment by the end of April 30th. Detailed submission instructions will be added in due course.
The deadline for this work is Monday 30th April.
In this page (and in other pages for this module):
Pale yellow boxes indicate code or other material that should be the contents of a file — you will generally use an editor, such as Emacs, Scite or GEdit to enter/view the content.
Pale blue boxes indicate a place where you should be entering a command, e.g. at a command prompt in a terminal window.
Pale pink boxes indicate interactive use, with the input you should type in RED; other text is expected output from a program.
Hints and asides are written in pink italics.
You will need to choose a port to run your service on. To get a unique port number, try using your numeric uid. "getent passwd" will tell you your uid (and your gid).
The client uses a Socket to make a connection to the server. Once connected, the client prompts the user for a number (in the console; no need for a GUI), and sends it to the server. The server responds with the square of the number, which the client will print on the screen.
Keep going until the user submits the special number 999. The client should send the special number, then shut down.
Server listens for connections. When a connection is made, it should create a handler Thread which waits for numbers to be sent from the client. After receiving a number, it should calculate the square and send it back to the client.
Repeat until the client sends the special number 999.
What happens if the client tries to connect and no server is running?
What happens if one end just stops in the middle (client never sends another number; server never responds to a request)?
Test it over two machines. Try running more than one client against one server.
Test your client with another person's server; and vice versa.
Question 2 — Online Voting (assessed)
You need your usual UoL username password to connect; you can post anonymously, or login within the forum using your informatics linux username/password. All posts are moderated, so might not show up immediately.
The worksheet is presented in several phases to lead you towards a working solution. If you do not make it to the final phase, you should hand in as far as you have managed. If you do make it to the final phase, you only need to hand that in.
The theme of the exercise is to produce a simple client/server on-line voting system. The server will:
be setup with a fixed candidate list (the BallotPaper) and a list of eligible voters (the VoterList);
accept connections from clients (voters); send the voter a copy of the list of candidates and then record their vote.
It is important that you write your code in a java package called "CO2017.exercise3. This will simplify the marking process. To achieve this, you need to start each code file with a line like this (replaceabc123with your own username).
package CO2017.exercise3.abc123;If you are using eclipse or a similar IDE, it should have tools available to make it simple to write your code in a specific package, and/or to move code from one package to another.
In this phase, you will produce simple client and server programs to implement a protocol for online voting. The client and server will make use of the basic data structure classes from Phase 0.
Note that 70% of the CW3 assessment marks are for phase 1.
This section describes the protocol that the client and server use to communicate. Note that the messages passed between client and server using the protocol are not necessarily the same as the messages that will be displayed on-screen for the user of the system.
In all cases
vid, bnum are decimal integers (in String form) representing unique voter and ballot identifiers;
vote is a single character vote;
BALLOT, OK, END, etc are literal Strings values;
similarly, Xvid, Xbnum, Xvote and XXXX are values that do not match the expected ones (used in the transaction so far);
values on a single line are separated with colons (':');
lines are to be terminated where shown;
data should be flushed after each message;
{close connection} indicates that the socket connection should be closed
Here are some typical protocol transactions between an individual client and the server.