Added an update function to client

This commit is contained in:
Manuel Cortez 2022-04-08 15:18:39 -05:00
parent 1aa7491624
commit 178163420a
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790

View File

@ -13,6 +13,10 @@ class client(object):
def run(self): def run(self):
self.running = True self.running = True
while self.running: while self.running:
self.update()
time.sleep(0.001)
def update(self):
event = self.host.service(0) event = self.host.service(0)
if event.type == enet.EVENT_TYPE_CONNECT: if event.type == enet.EVENT_TYPE_CONNECT:
if hasattr(self, "connected"): if hasattr(self, "connected"):
@ -24,7 +28,6 @@ class client(object):
data = event.packet.data data = event.packet.data
data_dict = json.loads(data) data_dict = json.loads(data)
self.network(event, data_dict) self.network(event, data_dict)
time.sleep(0.001)
def send_data(self, channel, data, reliable=True): def send_data(self, channel, data, reliable=True):
data_str = json.dumps(data, ensure_ascii=False) data_str = json.dumps(data, ensure_ascii=False)