try: s.connect(addr.split(":")[0], port=int(addr.split(":")[1])) print("Waiting to be assigned a number") num = int(s.receive()) print("Received number!") if not num: print("There was an error with the connection.") print("Reconnecting...") continue elif num == 1: print("Getting direct connection") peer = GameSocket(is_server=True, port=PORT) data = peer.getName()[0] + ":" + str(peer.getName()[1]) s.send(data) peer.acceptConnections(1) peer.send(1) else: print("Getting direct connection") peer = GameSocket() data = s.receive() peer.connect(data.split(":")[0], port=int(data.split(":")[1])) s.send(peer.receive()) s.disconnect() print("Connection acquired") connected = True except:
from GameSocket import * s=GameSocket(is_server=True) print("Address: "+s.getName()[0]+":"+str(s.getName()[1])) while True: try: s.acceptConnections(2) print("Making match: "+str(s.peers[0][1])+" "+str(s.peers[1][1])) #Assign player numbers s.send(1,peer=s.peers[0]) s.send(2,peer=s.peers[1]) #Create a direct connection data=s.receive(peer=s.peers[0]) s.send(data,peer=s.peers[1]) result=int(s.receive(peer=s.peers[1])) if result==1: print("Match made.") else: print("Clients failed to connect.") print("Terminating connections.") s.disconnect(peer=s.peers[0]) s.disconnect(peer=s.peers[1]) s.removePeers() except Exception as e: print("\n"+str(e)+"\n") print("Notifying active peers of the error.") for peer in s.peers: