You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
776 B
39 lines
776 B
import signal
|
|
import socketio
|
|
|
|
SERVER_0_IP = "localhost"
|
|
SERVER_0_PORT = 4999
|
|
SERVER_1_PORT = 5002
|
|
SERVER_1_NAME = "server_2"
|
|
|
|
sio = socketio.Client()
|
|
|
|
@sio.event
|
|
def connect():
|
|
print("I'm connected!")
|
|
sio.emit("register", {"name": SERVER_1_NAME, "ip": SERVER_0_IP, "port": SERVER_1_PORT})
|
|
|
|
@sio.event
|
|
def connect_error(data):
|
|
print("The connection failed!")
|
|
|
|
@sio.event
|
|
def disconnect():
|
|
print("I'm disconnected!")
|
|
|
|
@sio.event
|
|
def heartbeat():
|
|
print("Received heartbeat")
|
|
|
|
def main():
|
|
sio.connect(f"http://{SERVER_0_IP}:{SERVER_0_PORT}")
|
|
sio.wait()
|
|
|
|
def exit_handler(sig, frame):
|
|
sio.disconnect()
|
|
exit(0)
|
|
|
|
if __name__ == "__main__":
|
|
signal.signal(signal.SIGINT, exit_handler)
|
|
signal.signal(signal.SIGTERM, exit_handler)
|
|
main()
|
|
|