File tree 3 files changed +15
-2
lines changed
ProtocolImplementation/ClientProtocolImplementation
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ def input(self):
19
19
raise ConnectionError ("Server not confirming" )
20
20
if not self .status_handler .is_code ("End" , self .s .recv (CODEBYTES )):
21
21
raise ConnectionError ("Server not ending" )
22
+ except KeyboardInterrupt :
23
+ raise KeyboardInterrupt
22
24
except :
23
25
print ("Error with transmission. Try again" )
24
26
Original file line number Diff line number Diff line change @@ -21,13 +21,19 @@ def start(self):
21
21
file_handler .download ()
22
22
23
23
def main ():
24
- ip , port = input ("Ip address: " ), input ("Port: " )
24
+ try :
25
+ ip , port = input ("Ip address: " ), input ("Port: " )
26
+ except KeyboardInterrupt :
27
+ print ("\n \n Stopping..." )
28
+ exit ()
25
29
s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
26
30
try :
27
31
s .connect ((ip , int (port )))
28
32
print (f"Connected to { s .getsockname ()} " )
29
33
user_handler = UserHandler (s )
30
34
user_handler .start ()
35
+ except KeyboardInterrupt :
36
+ print ("\n \n Exiting..." )
31
37
finally :
32
38
s .close ()
33
39
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ def handle(self):
51
51
h/H: Help
52
52
q: Exit""" )
53
53
elif cmd == 'q' :
54
+ protocol_handler .close_connection ()
54
55
break
55
56
else :
56
57
protocol_handler .send_output ("Command not found" )
@@ -67,7 +68,11 @@ def main():
67
68
datefmt = "%H:%M:%S" )
68
69
logging .info ("Server running..." )
69
70
server = ThreadedTCPServer ((HOST , PORT ), ThreadedTCPRequestHandler )
70
- server .serve_forever ()
71
+ try :
72
+ server .serve_forever ()
73
+ except KeyboardInterrupt :
74
+ print ("\n Stopping server. Waiting for the termination of all open connections..." )
75
+ server .server_close ()
71
76
72
77
73
78
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments