fix: open/close client sockets
This commit is contained in:
parent
d369b8e1b1
commit
253ccdf1ff
@ -52,11 +52,10 @@ class UDPClient:
|
||||
if not self.pong_received:
|
||||
return
|
||||
|
||||
while True:
|
||||
try:
|
||||
client_socket = socket(AF_INET, SOCK_DGRAM)
|
||||
client_socket.connect((self.server_name, self.server_port))
|
||||
|
||||
try:
|
||||
while True:
|
||||
# get command from user
|
||||
command = input(f"myftp> - {self.mode} - : ").strip().lower()
|
||||
|
||||
@ -112,10 +111,11 @@ class UDPClient:
|
||||
)
|
||||
continue
|
||||
|
||||
client_socket.send(request_payload.encode("utf-8"))
|
||||
client_socket.sendto(request_payload.encode("utf-8"), (self.server_name, self.server_port))
|
||||
|
||||
modified_message = client_socket.recv(2048)[1:]
|
||||
|
||||
print(modified_message.decode())
|
||||
client_socket.close() # type: ignore
|
||||
|
||||
except ConnectionRefusedError:
|
||||
print(
|
||||
@ -125,6 +125,8 @@ class UDPClient:
|
||||
print(
|
||||
f"myftp> - {self.mode} - {error} happened."
|
||||
)
|
||||
finally:
|
||||
client_socket.close()
|
||||
|
||||
# ping pong UDP
|
||||
def check_udp_server(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user