如何在ZeroMQ python中正确声明套接字类型?

问题描述 投票:0回答:1

我有一个奇怪的问题。我为不和谐的bot开发了一个Web界面,并使用ZeroMQ在bot的进程和fastAPI进程之间进行通信。我的程序是结构化的,因此fastAPI进程发送ZeroMQ REQ。我的discord bot充当“ [server”,因为它提供了信息,而fastAPI进程充当了客户端。这种特定的方法试图让我的不和谐机器人获取在线成员,然后将其发送回请求者。这是我的代码:

服务器端: (为简化起见,不相关的部分)] >>

import asyncio

import zmq
import zmq.asyncio


async def openWebServerInterface():
    zmqctx = zmq.asyncio.Context()
    s = zmqctx.socket(zmq.REP)
    s.connect('tcp://127.0.0.1:1234')
    print('waiting on request...')
    request = await s.recv_string()
    if request == "gimmethedata":
        print("sending online people")
        s.send_string(await returnOnline())
    print("data request sent!")
    s.close()

async def returnOnline():
    message = "this will return my online members"
    return message

asyncio.run(openWebServerInterface())

客户端:

async def listenForResponse():
    await openBotConnection()
    print("logo interface opened!")
    r = zmqctx.socket(zmq.REP)
    print("socket connected, waiting for response")
    reply = await r.recv_string()
    print(reply)
    return reply

async def openBotConnection():
    s = zmqctx.socket(zmq.REQ)
    s.connect('tcp://127.0.0.1:1234')
    await s.send_string("gimmethedata")
    print("data request sent!")
    s.close()

@app.get("/")
async def root():
    print("listing for logo's response!")
    return await listenForResponse()

我收到的错误消息位于服务器程序上(运行“客户端”程序没有问题)。错误如下:

Traceback (most recent call last):File "E:/DiscordBotContainer/ServerSideTestFile", line 23, in <module>asyncio.run(openWebServerInterface())File "*\AppData\Local\Programs\Python\Python38\lib\asyncio\runners.py", line 43, in runreturn loop.run_until_complete(main)File "*\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete返回future.result()File "E:/DiscordBotContainer/fuck it", line 9, in openWebServerInterfaces = zmqctx.socket(zmq.REP)File "*\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\sugar\context.py", line 204, in sockets = self._socket_class(self, socket_type, **kwargs)File "*\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\_future.py", line 144, in __init__self._init_io_state()File "*\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\asyncio\__init__.py", line 53, in _init_io_stateself.io_loop.add_reader(self._fd, lambda : self._handle_events(0, 0))File "*\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_readerraise NotImplementedError

我的直觉使我认为这是服务器端套接字声明的问题,但我在客户端使用完全相同的语法声明套接字没有问题。

我有一个奇怪的问题。我为不和谐的bot开发了一个Web界面,并使用ZeroMQ在bot的进程和fastAPI进程之间进行通信。我的程序是结构化的,因此fastAPI ...

python python-3.x zeromq
1个回答
0
投票

Q

© www.soinside.com 2019 - 2024. All rights reserved.