I'm doing this as an assignment, and it says that I have to modify the client file so that the time appears on the screen required from the time I send the message until the time the response from the server arrives and to experiment with different dimensions and messages types.
I've been looking through old archived videos inside the platform but found no such thing when the teacher was doing that.
As I started to run both client and server, nothing shows on it, and this is where I'm stuck.
client
import socket
import time
server_port = 21060
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
input_s = 'Good morning, and welcome!'
time = 'The time is 8:46 am.'
temperature = 'Current temperature is 96ยฐF'
start_time = time.time()
client_socket.sendto(bytes(input_s, encoding='utf8'), ('127.0.0.1', server_port))
input_s_modified, address = client_socket.recvfrom(65535)
end_time = time.time()
elapsed_time = end_time - start_time
print('[CLIENT] Response from server {}, is: "{}"'.format(address, str(input_s_modified.decode('utf8'))))
print("Elapsed time:", elapsed_time, "seconds")
client_socket.close()
server
import socket
server_port = 21060
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('127.0.0.1', server_port))
print ('[SERVER] Listening at: {}'.format(server_socket.getsockname()))
while True:
message, address = server_socket.recvfrom(65535)
modified_message = str(len(str(message).split(",")))
print ('[SERVER] The client at {}, originally sent: {}'.format(address, repr(message)))
server_socket.sendto(bytes('Server is sending back: "{}".'.format(modified_message), encoding='utf8'), address)
server_socket.close()