feat(udp): use true byte representation
- added an option to make client without debug
This commit is contained in:
parent
d78eb940cd
commit
5519be9222
3
Makefile
3
Makefile
@ -9,6 +9,9 @@ server:
|
||||
client:
|
||||
docker exec -it project-ftp_client-1 python client.py --directory /client_directory --debug 1
|
||||
|
||||
client-no-debug:
|
||||
docker exec -it project-ftp_client-1 python client.py --directory /client_directory
|
||||
|
||||
clean:
|
||||
docker-compose down --volumes
|
||||
|
||||
|
@ -74,7 +74,7 @@ class UDPClient:
|
||||
|
||||
# help
|
||||
elif command == "help":
|
||||
request_payload: str = help_requrest_opcode + "00000"
|
||||
request_payload: str = help_requrest_opcode + "00000" # 10000000
|
||||
print(
|
||||
f"myftp> - {self.mode} - Asking for help from the server"
|
||||
) if self.debug else None
|
||||
@ -113,7 +113,10 @@ class UDPClient:
|
||||
)
|
||||
continue
|
||||
|
||||
client_socket.sendto(request_payload.encode("utf-8"), (self.server_name, self.server_port))
|
||||
# convert the payload to bytes so it can be sent to the server
|
||||
byte_representation_req_payload: bytes = bytes([int(request_payload, 2)])
|
||||
|
||||
client_socket.sendto(byte_representation_req_payload, (self.server_name, self.server_port))
|
||||
|
||||
response_payload = client_socket.recv(2048)
|
||||
|
||||
|
@ -48,8 +48,16 @@ class UDPServer:
|
||||
try:
|
||||
while not shut_down:
|
||||
message, clientAddress = self.server_socket.recvfrom(2048)
|
||||
|
||||
# decode for quick and dirty commands like ping and list server files
|
||||
# outside of the scope of the project
|
||||
try:
|
||||
request_payload = message.decode()
|
||||
|
||||
except UnicodeDecodeError:
|
||||
# most commands (get, put, summary ...) will be handled by this catch block
|
||||
request_payload: str = bin(int.from_bytes(message, byteorder='big'))[2:]
|
||||
|
||||
print(
|
||||
f"myftp> - {self.mode} ------------------------------------------------------------------"
|
||||
) if self.debug else None
|
||||
|
Loading…
x
Reference in New Issue
Block a user