@@ -37,13 +37,22 @@ def getmyip():
3737
3838#The default ip is your local one and port is 5050
3939def bind (TCP_IP = getmyip (), TCP_PORT = 5050 ):
40- s = create ()
41- s .bind ((TCP_IP , TCP_PORT ))
42- print ("Ready to connect on: " + TCP_IP + " on port:" , TCP_PORT )
40+ try :
41+ s = create ()
42+ s .bind ((TCP_IP , TCP_PORT ))
43+ print ("Ready to connect on: " + TCP_IP + " on port:" , TCP_PORT )
44+ except OSError :
45+ print ("Cannot connect please check your PC" )
46+ exit ()
47+
48+ except :
49+ print ("Ready to connect on: " + TCP_IP + " on port:" , TCP_PORT )
50+
4351 s .listen (1 )
4452 conn , addr = s .accept ()
4553 print ('Connection address:' , addr )
4654 return conn
55+
4756
4857def create ():
4958 try :
@@ -75,6 +84,10 @@ def connect(remote_ip, port):
7584 except ConnectionRefusedError :
7685 print ("Connection Refused Error (likely because other machine's port isn't open)" )
7786 return False
87+
88+ except TimeoutError :
89+ print ("Connection timed out" )
90+ return False
7891
7992 except ConnectionRefusedError :
8093 print ("Connection Refused Error (likely because other machine's port isn't open)" )
@@ -105,4 +118,4 @@ def receive(s, buff=4069):
105118 except ConnectionAbortedError :
106119 print ("Error ConnectionAbortedError" )
107120 return False
108- #connect(socket.gethostbyname(socket.gethostname()), 5005)
121+
0 commit comments