feat(udp): Basic command parsing, bye command implemented
This commit is contained in:
		@@ -23,11 +23,27 @@ class UDPClient:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        client_socket.connect((self.server_name, self.server_port))
 | 
					        client_socket.connect((self.server_name, self.server_port))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        message = input("input lowercase sentence: ")
 | 
					        while True:
 | 
				
			||||||
 | 
					 | 
				
			||||||
        client_socket.send(message.encode())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            try:
 | 
					            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)
 | 
					                modified_message = client_socket.recv(2048)
 | 
				
			||||||
                print(modified_message.decode())
 | 
					                print(modified_message.decode())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,7 +71,7 @@ class UDPClient:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # If the server responds, consider the address valid
 | 
					            # If the server responds, consider the address valid
 | 
				
			||||||
            print(
 | 
					            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
 | 
					            # code reached here meaning no problem with the connection
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user