giants-stupid-server/giants/masterserver.py
2021-02-16 12:24:15 +01:00

27 lines
782 B
Python

import socket
import threading
import time
import traceback
class MasterServer:
def __init__(self, server):
self.server = server
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.masterserverip = "gckms.no-ip.org"
self.masterserverport = 27900
def register_and_run(self):
register_thread = threading.Thread(target=self._register)
register_thread.start()
return register_thread
def _register(self):
while True:
print("Sending register")
try:
self.socket.sendto(("0"+str(self.server.listen_port)).encode("ascii"), (self.masterserverip, self.masterserverport))
except:
traceback.print_exc()
time.sleep(120)