lu.se

Datavetenskap

Lunds Tekniska Högskola

Denna sida på svenska This page in English

Server Integration and The Client Side

Objectives

The main objective of the exercise is to build a chat system enabling a group of participants to discuss in real time. The exercise is divided into two sessions. The objectives of the second session are to:

  • Integrate the multithreaded producers/consumer to the server
  • Create a TCP client

Summary of the Work

Each group will have to:

  • Integrate the monitor to coordinate the threads into the TCP server so that no message is lost.
  • Manage the list of active participants.
  • Write a TCP client.

Reading Assignments

Read the rest of chapter 5 on threads from the book Java Network Programming by Elliotte Rusty Harold, pp. 123-149;

Programming

Server Integration

In the previous session, you have programmed a TCP server and threads. You will now integrate them so that they can function as a chat server.

  1. Determine which data are necessary to manage the chat participants. Design a class to represent them.
  2. Build a list mechanism, for instance using the Vector built-in class, to store the active participants.
  3. Integrate the monitor you developed in the previous lab to the TCP server so that participants can connect using telnet. All the participants must receive the sequence of messages in the same order.
  4. You will use text-based commands: 'M: Content of the message' to send a message to all the participants, 'E: Content of the message' to echo the message to the user for testing purposes, and 'Q:' to disconnect. You may define other commands if you want.
  5. Be aware that participants can interrupt their session at any time.

Creating a Client

You have used telnet as the client of your server. You will now write your own TCP client in Java. The synopsis of the client command is java ChatClient machine port. The machine address will be either a domain name or dotted numbers. The program reads continuously command strings from the keyboard and sends them to a server identified by machine and port until the user stops it.

  1. Write the code that parses the command line.
  2. Use the Socket class to connect to the server.
  3. Write a loop that reads lines from the keyboard and, depending on your protocol, sends a string or the first character of the line to the server. Use the getInputStream() and getOutputStream() methods of the Socket class to obtain the socket streams.
  4. Make sure that your client can asynchronously send and receive messages. (Hint: use threads)