messenger_server.request_handler module¶
-
exception
messenger_server.request_handler.
InvalidRequestError
¶ Bases:
Exception
-
class
messenger_server.request_handler.
RequestHandler
(request, client_address, server)¶ Bases:
socketserver.BaseRequestHandler
Class used to handle each TCP request.
As required by
socketserver.BaseServer
this class inherits fromsocketserver.BaseRequestHandler
and is provided to thesocketserver.TCPServer
to be instantiated for every incoming request and call thehandle()
function.Parameters: - request (
socket.socket
) – a socket created by the request - prefixes_to_methods (dict(int, function)) – mapping of requests’ prefixes to appropriate handling methods
-
handle
()¶ Retrieve incoming data and execute adequate handler function.
When data has been received from the socket, the first byte is used to determine the type of the request, in accordance with the protocol. Corresponding method is then passed the received data minus the first byte.
-
handle_add_contact_request
(add_contact_request)¶ Perform adding user’s contact and send adequate response.
Parameters: add_contact_request (bytes) – Add-contact request without the prefix
-
handle_get_contacts_request
(get_contacts_request)¶ Perform fetching user’s contact list and send adequate response.
Parameters: get_contacts_request (bytes) – Get-contacts request without the prefix
-
handle_incoming_message
(incoming_message_request)¶ Perform passing a message to another user and other adequate actions.
Parameters: incoming_message_request (bytes) – Incoming message without the prefix
-
handle_login_request
(login_request)¶ Perform user log-in and send adequate response.
Parameters: login_request (bytes) – Log-in request without the prefix
-
handle_signup_request
(signup_request)¶ Perform user sign-up and send adequate response.
Parameters: signup_request (bytes) – Sign-up request without the prefix
- request (