Skip to content

Commit

Permalink
紧急修复ws连接问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xszyou committed Aug 15, 2023
1 parent f4752fb commit 98f83e2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/wsa_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def __producer_handler(self, websocket, path):
while self.__running:
await asyncio.sleep(0.000001)
message = await self.__producer()
if message and self.isConnect:
if message:
await websocket.send(message)


Expand All @@ -50,13 +50,17 @@ async def __handler(self, websocket, path):
task.cancel()
self.isConnect = False
util.log(1,"websocket连接断开:{}".format(self.__port))
if self.__port == 10002:
web_server_instance = get_web_instance()
web_server_instance.add_cmd({"is_connect": False})

async def __consumer(self, message):
self.on_revice_handler(message)

async def __producer(self):
if len(self.__listCmd) > 0:
message = self.on_send_handler(self.__listCmd.pop(0))
print(message)
return message
else:
return None
Expand All @@ -77,6 +81,7 @@ def on_connect_handler(self):
def on_send_handler(self, message):
return message


# 创建server
def __connect(self):
self.__event_loop = asyncio.new_event_loop()
Expand All @@ -91,7 +96,7 @@ def __connect(self):

# 往要发送的命令列表中,添加命令
def add_cmd(self, content):
if not self.__running or not self.isConnect:
if not self.__running or (not self.isConnect and self.__port == 10002):
return
jsonObj = json.dumps(content)
self.__listCmd.append(jsonObj)
Expand Down Expand Up @@ -129,11 +134,15 @@ def on_revice_handler(self, message):
pass

def on_connect_handler(self):
pass
web_server_instance = get_web_instance()
web_server_instance.add_cmd({"is_connect": True})


def on_send_handler(self, message):
# util.log(1, '向human发送 {}'.format(message))
util.log(1, '向human发送 {}'.format(message))
return message



#ui端server
class WebServer(MyServer):
Expand Down Expand Up @@ -162,6 +171,8 @@ def on_connect_handler(self):

def on_send_handler(self, message):
return message




#单例
Expand Down

0 comments on commit 98f83e2

Please sign in to comment.