Java Chat Room

Multithread server and client

Posted by Jiayi.Liu on July 3, 2019

Here is two major reference for this project: DomHeal and Laity000. Laity000’s project also has his design process of his chatroom which helps a lot.

Communication

What Protocal / Framework

    It is easy to see that we need a server - client design in thie project. So, the first to consider should be how can they communicate, which is “what is the protocal” we can use? What framework / template to use?

    For protocal, basically we have:

  • Socket (TCP) Server
  • HTTP Server

    For frameworks, we have:

  • Java.net package
  • Spring Boot (mostly for web application)

Server Design

    To reduce requests blocking in server end, it is normal to use threads pool or create new thread for each request in the server.

    According to this tutorial, there are two ways to start a new Thread – Subclass Thread and implement Runnable interface. There is no need of subclassing Thread when a task can be done by overriding only run() method of Runnable interface. Thread has a construction that accept Runnable as input.