Question
def close(self): TODO: close this client :return: VOID def connect(self, server_ip_address, server_port): TODO: Create a connection from client to server :param server_ip_address:
def close(self): """ TODO: close this client :return: VOID """
def connect(self, server_ip_address, server_port): """ TODO: Create a connection from client to server :param server_ip_address: :param server_port: :return: """ #TODO: 1. use the client socket implement a connection from this client to the server using the server ip and port
#TODO: 2. once the client creates a succesful connection the server will send the client id to this client. # call the method set_client_id() to implement that functionality.
# data dictionary already created for you. Don't modify. data = {'student_name': self.student_name, 'github_username': self.github_username, 'sid': self.sid}
#TODO 3. send the above data to the server. using the send method which has been already implemented for you.
while True: # client is put in listening mode to retrieve data from server. data = self.receive() if not data: break # do something with the data self.close()
def send(self, data): """ Serializes and then sends data to server :param data: :return: """ data = pickle.dumps(data) # serialized data self.client.send(data)
def receive(self, MAX_BUFFER_SIZE=4090): """ Desearializes the data received by the server :param MAX_BUFFER_SIZE: Max allowed allocated memory for this data :return: the deserialized data. """ raw_data = self.client.recv(MAX_BUFFER_SIZE) # deserializes the data from server return pickle.loads(raw_data)
def set_client_id(self): """ Sets the client id assigned by the server to this client after a succesfull connection :return: """ data = self.receive() # deserialized data client_id = data['clientid'] # extracts client id from data self.client_id = client_id # sets the client id to this client print("Client id " + str(self.client_id) + " assigned by server")
Finish code in Bold
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started