We developed a chat application in Python to implement a Client-Server Model via Transmission Control Protocol (TCP). We built this to meet the following base requirement :
The chat service provider (i.e. server) must be able to manage multiple clients in the system without a significant drop in performance.
The server and clients are managed via multiprocessing
as these represent seperate entities (i.e. each have their own code section and Global Interpreter Lock (GIL)).
Handshakes are performed and messages are handled (i.e. received/sent from client to server) via multithreading
for concurrency.
There has been error handling implemented for both the chat server and clients to appropriately handle disconnections, including a client leaving the system, as well as server shutdown.
We have implemented this, such that the same client can attempt reconnection and communicate via a reestablished server application.
The server threads which handle client messages implement Inter-Process Communication (IPC) via memory sharing. They have read-write access to the socketInfo
data field, which is a list
of dicts
(i.e. with the socket
object and address
tuple).
If a client socket is closed and a server thread is unable to successfully send a message, it removes the socket information from the socketInfo
data field in a critical section.
This is to ensure other threads are made aware of this client leaving the system, as well as to avoid subsequent communication attempts by the current thread.
We have illustrated the following UML Sequence Diagram to describe the high-level interactions in our program.
Note that all connections and disconnections are implemented via TCP.
We have uploaded our Final Demo on Youtube.
Demo.mp4
This was completed as part of the CPEN 333 - Software Design course in The University of British Columbia Electrical and Computer Engineering undergraduate program. We received tremendous support and guidance from Dr. Farshid Agharebparast.