3. API Reference

3.1. Server

class clientThread.ClientThread

The ClientThread is a thread class. Its instance is created as a thread that is spawned by the serverSocket module for handling a new client. For each new user that connects to the server, we would create a new thread for handling that client.

__init__(self, threadID, name, counter, clientSocket, allClients)

This __init__ method overrides the __init__ function of the Thread class in the threading module. It calls the __init__ function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread.

Parameters:
  • threadID – unique ID given to each thread
  • name – name given to the thread
  • counter – number of threads of this name generated
  • clientSocket – Socket instance of the client.
  • allClients – a list of Socket instances of all clients connected to the server
Return type:

None

run(self)

The run method is executed when a thread is started. Here the run method is used to spawn a new thread called clientThreadReadHandle that handles client read operations.

Return type:None
class clientThreadReadHandle.ClientThreadReadHandle

The ClientThreadReadHandle is a thread class. Its instance is created as a thread that is spawned by the ClientThread class. It is used for the purpose of handling communication between a server and a specific client. It reads data that is sent by client and broadcasts it to all other clients

__init__(self, threadID, name, counter, clientSocket, allClients)

This __init__ method overrides the __init__ function of the Thread class in the threading module. It calls the __init__ function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread.

Parameters:
  • threadID – unique ID given to each thread
  • name – name given to the thread
  • counter – number of threads of this name generated
  • clientSocket – Socket instance of the client.
  • allClients – a list of Socket instances of all clients connected to the server
Return type:

None

run(self)

This method is executed when a thread is started. Here the run method checks the client it is assigned to for any messages and if found broadcasts it to all other clients connected to the server.

Return type:None

3.2. Client

class writingThread.WritingThread

The WritingThread is a thread class. Its instance is created as a thread that is spawned by the clientSocket module for sending data from the client to the server. It reads data from the standard input and sends it to the server.

__init__(self, threadID, name, counter, clientSocket)

This __init__ method overrides the __init__ function of the Thread class in the threading module. It calls the __init__ function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread.

Parameters:
  • threadID – unique ID given to each thread
  • name – name given to the thread
  • counter – number of threads of this name generated
  • clientSocket – Socket instance of the client.
Return type:

None

class readingThread.ReadingThread

The ReadingThread is a thread class. Its instance is created as a thread that is spawned by the clientSocket module.

__init__(self, threadID, name, counter, clientSocket)

This __init__ method overrides the __init__ function of the Thread class in the threading module. It calls the __init__ function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread.

Parameters:
  • threadID – unique ID given to each thread
  • name – name given to the thread
  • counter – number of threads of this name generated
  • clientSocket – Socket instance of the client.
Return type:

None

run(self)

The run method contains code that must be executed when the thread is started. Here the run method checks the clientSocket for any messages that the server has sent. If so the message is displayed on the client’s console.

Return type:None