Starting from:

$29

Assignment 8 Sockets in Java

Assignment 8 – 110/100 points possible
The goal of this assignment is to gain experience with network programming, specifically with
sockets in Java. This assignment will also require you to develop a server and client
simultaneously, which is an important skill in itself. The client will allow the user to enter a
simple message to be sent to the server and then will print the message entered by the
previous user to connected to the server. The server, in turn, will continuously accept socket
connections, storing the current received message and sending the previous message.
1. [20] Create two classes, one for your client and one for your server. Each class will need a
main method so that both classes can be executed.
2. [40] Implement your client to prompt the user for a message, send that message to the
server (hint: see java.net.Socket), and then print the received message.
3. [40] Implement your server to loop indefinitely, accepting socket connections (hint: see
java.net.ServerSocket). When a socket is accepted, send the message received on the previous
socket. If this is the first socket to connect (i.e., there is no previous message), send the
message "You're the first to connect!" Then store the received message for the next user. The
server should terminate if the message received is "shutdown".
4. [+10] (Extra credit) Create a GUI for the client. You can either create a GUI from scratch or
use the existing dialogs in javax.swing.JOptionPane.
Your output should look something like (after running the client twice):
Enter a message:
Hello!
The last user wrote: You're the first to connect!
Enter a message:
World!
The last user wrote: Hello!

More products