In this lab you will implement the Battleship game, whose protocol we designed together in class.
In writing your server, it is important that you conform to this protocol. Failure to do so will prevent the client from communicating with your server, and a crash or failure of some sort will surely ensue. There are two aspects of a protocol that are especially important:
|A single byte||void writeByte(int)||byte readByte()|
|Two-byte integer||void writeShort(int)||short readShort()|
|Four-byte integer||void writeInt(int)||int readInt()|
|Java String||void writeUTF(String)||String readUTF()|
|Makes service available at port 3001 and waits for a connection|
|Connects to the server at port 3001|
|Spawns a new thread to service this client|
| Sends the following:
| Reads in what the client sent.
Send the following:
|The observer story continues after this table. The player story continues below|
|Waits for next message from the server|
| Send the following game
| Receives the game configuration message and responds with the
following ships placement message:
| Receives what was sent in the row above. Sends one of the following
back to the client as a String:
|From here, the server sends all messages to both clients.|
| Sends one of the following messages, as appropriate:
| Reacts to the message received from sender:
| Once a client has entered a an observer, or as a player
who has finished the configuration stage, you must also be prepared to
receive or send the following message.
Because this feature is offered asynchronously, your client and server must be prepared to receive and send from and to the socket at any time. This implies that receiving and sending must be performed in separate threads. Without a separate thread, any attempt to read from the socket would block, preventing outgoing messages from being sent.
In this way, an observer client can show both boards in progress during the game.
So, an observer can help a player cheat since the observer sees both boards.
These clients will allow you to test your server code. At least one client connecting to your server can be the dummy client, and then you can either have another dummy client play randomly against the other, or you can play against the dummy.
When you done with this studio, you must be cleared by the TA to receive credit.
- Commit all your work to your repository!If you do not commit, the TAs cannot grade your work and you will receive a 0 for this assignment!
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so