feat(udp): Basic command parsing, bye command implemented

This commit is contained in:
minhtrannhat 2023-11-27 00:21:09 -05:00
parent d1952d846b
commit 5364d35a3d
Signed by: minhtrannhat
GPG Key ID: E13CFA85C53F8062

View File

@ -23,11 +23,27 @@ class UDPClient:
client_socket.connect((self.server_name, self.server_port))
message = input("input lowercase sentence: ")
client_socket.send(message.encode())
while True:
try:
# get command from user
while (command := input(f"myftp> - {self.mode} - : ")) not in [
"put",
"get",
"summary",
"change",
"help",
"bye",
]:
print(
f"myftp> - {self.mode} - : Invalid command. Supported commands are put, get, summary, change and help"
)
if command == "bye":
client_socket.close()
print(f"myftp> - {self.mode} - Session is terminated")
break
client_socket.send(command.encode())
modified_message = client_socket.recv(2048)
print(modified_message.decode())
@ -55,7 +71,7 @@ class UDPClient:
# If the server responds, consider the address valid
print(
f"myftp> - {self.mode} - Server at {self.server_name} is valid. Response received: {data.decode('utf-8')}"
f"myftp> - {self.mode} - Server at {self.server_name}:{self.server_port} is valid. Response received: {data.decode('utf-8')}"
)
# code reached here meaning no problem with the connection