Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

Client-Server Communications Project

The purpose of this project is for you to become familiar with Java Socket communications. To do this
you will first write a Client program to communicate with a Server already written and after that you
will write the Server program.
This Client-Server application is a simple messaging system where all messages sent to the server are
sent to all currently connected clients. The messages are just plain character strings.
Writing a GUI is not required (but it is a good idea so you gain more GUI skill).
There is a server running at 152.117.177.191 port 54321. You can use TELNET to connect to it and
test it. Note that this server is not accessible through the PLU firewall (unless, of course, you set up an
SSH tunnel).
You may work in pairs on this project.
Client pseudo-code:
Thread One (Sending):
1.
Open a Socket to the Server and get the IO streams (in, out)
2.
while not done
1.
get a message from the user
2.
write the message to out
3.
Close the IO streams and Socket
Thread Two (Receiving):
1.
while( true )
1. read a message from the Server
2. display the message to the user

Server pseudo-code:
Thread One (Accepting Connections):
1.
Open a ServerSocket, serverSocket
2.
while not done
1.
socket = serverSocket.accept()
2.
get the IO streams (in, out)
3.
add this connection to the list of connections
4.
new Connection( socket, in, out, this ) // separate Thread
3.
Close serverSocket
Thread Two (Sending Messages):
sendMessage( message )
1. for all connections
1. write message to out
Thread(s) Three+ (A Connection instance): // like the Client above with two threads
Thread 1:
Connection( socket, in, out, this )
1. while not done
2. get a message from the user
3. this.sendMessage (message )
Thread 2:
1. while( true )
1. get message from server
2. display message to user

You might also like