Added an update function to client
This commit is contained in:
		| @@ -13,19 +13,22 @@ class client(object): | |||||||
|     def run(self): |     def run(self): | ||||||
|         self.running = True |         self.running = True | ||||||
|         while self.running: |         while self.running: | ||||||
|             event = self.host.service(0) |             self.update() | ||||||
|             if event.type == enet.EVENT_TYPE_CONNECT: |  | ||||||
|                 if hasattr(self, "connected"): |  | ||||||
|                     self.connected(event.peer) |  | ||||||
|             elif event.type == enet.EVENT_TYPE_DISCONNECT: |  | ||||||
|                 if hasattr(self, "disconnected"): |  | ||||||
|                     self.disconnected(event.peer) |  | ||||||
|             elif event.type == enet.EVENT_TYPE_RECEIVE: |  | ||||||
|                 data = event.packet.data |  | ||||||
|                 data_dict = json.loads(data) |  | ||||||
|                 self.network(event, data_dict) |  | ||||||
|             time.sleep(0.001) |             time.sleep(0.001) | ||||||
|  |  | ||||||
|  |     def update(self): | ||||||
|  |         event = self.host.service(0) | ||||||
|  |         if event.type == enet.EVENT_TYPE_CONNECT: | ||||||
|  |             if hasattr(self, "connected"): | ||||||
|  |                 self.connected(event.peer) | ||||||
|  |         elif event.type == enet.EVENT_TYPE_DISCONNECT: | ||||||
|  |             if hasattr(self, "disconnected"): | ||||||
|  |                 self.disconnected(event.peer) | ||||||
|  |         elif event.type == enet.EVENT_TYPE_RECEIVE: | ||||||
|  |             data = event.packet.data | ||||||
|  |             data_dict = json.loads(data) | ||||||
|  |             self.network(event, data_dict) | ||||||
|  |  | ||||||
|     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) | ||||||
|         data_bytes = bytes(data_str, "utf-8") |         data_bytes = bytes(data_str, "utf-8") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user