nng to pynng pub/sub. 客户端未收到任何消息
nng to pynng pub/sub. No messages recieved by client
我有以下服务器(C++(:
#include <nng/nng.h>
#include <nng/protocol/pubsub0/pub.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <unistd.h>
void
fatal(const char *func, int rv)
{
fprintf(stderr, "%s: %sn", func, nng_strerror(rv));
}
int main(int argc, char* argv[]){
nng_socket sock;
int rv;
std::string url = "tcp://0.0.0.0:" + std::to_string(5563);
if ((rv = nng_pub0_open(&sock)) != 0) {
fatal("nng_pub0_open", rv);
}
if ((rv = nng_listen(sock, url.c_str(), NULL, 0)) < 0) {
fatal("nng_listen", rv);
}
while(1){
std::string msg = std::string("msg");
//if ((rv = nng_send(sock, (void*)frame, bpp * nImgW * nImgH, 0)) != 0) {
if ((rv = nng_send(sock, (void*)msg.c_str(), 3, 0)) != 0) {
fatal("nng_send", rv);
}else{
std::cout << "Frame Sent... "<< std::endl;
}
sleep(1);
}
}
还有以下客户端(python(:
import pynng
from pynng import Pub0, Sub0, Timeout
cam_path = "tcp://127.0.0.1:5563"
with Sub0(dial=cam_path,recv_timeout=2000, topics=b'') as sub:
sub.recv_max_size = 0 #recieve msg of any size
while(1):
try:
print("waiting for msg")
img = sub.recv()
print(img)
except pynng.exceptions.Timeout as e:
print('Timed out, retrying...')
我不明白为什么没有消息到达客户端。我已经设置了主题和recv_max_size但仍然没有消息到达客户端。 我现在在这里做错了什么?
问:">我现在在这里做错了什么?
你碰巧盲目地假设事情以你的代码不尝试验证的方式发生。老汇编狼在开始代码之前曾经声明# ASSUME NOTHING
:o(
Pieter Hintjens',著名的AMQP/ZeroMQ福传大师(nanomsg/nng的哥哥(使用来自assert
-s的显式POSACK-s:
if ( ( aRetCODE = nng_pub0_open( &sock ) ) != 0 ) {
fatal( "nng_pub0_open",
aRetCODE );
}
assert( aRetCODE == 0 && "EXC: Pub0 socket failed to instantiate" );
if ( ( aRetCODE = nng_listen( sock, url.c_str(), NULL, 0 ) ) < 0 ) {
fatal( "nng_listen",
aRetCODE );
}
assert( aRetCODE == 0 && "EXC: Pub0 socket failed to .listen()" );
Python 还有一个类似的assert
工具,用于显式 POSACK 检查,因此值得使用它们来完善代码健壮性,因为 Pieter Hintjens 让 Martin Sustrik 在阅读 API 的任何地方都这样做:o(
assert rc == 0, "INF: some condition was not met for ( %r )" % someVariableNAME
很高兴为您的项目使用nng
/pynng
!
相关文章:
- boost::进程间消息队列引发错误
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- nng to pynng pub/sub. 客户端未收到任何消息
- 发送到另一个窗口的鼠标移动消息不执行任何操作
- 如果我在 Xbox UWP 应用程序上收到激活错误并且错误消息中没有任何有用的内容,该怎么办
- 按下Enter时如何输入错误消息,但没有给出任何答案
- ROS2 COLCON构建未在Windows中显示任何错误消息
- 任何人都有任何想法编写与C 旧手机中的消息作曲家以相同方式工作的程序
- 套接字记录未读取任何消息
- 为什么GetMessage在不发送任何消息的情况下退出我的程序
- 是否有任何消息总是出现在WM_LBUTTONDOWN和WM_LBUTTNUP之间
- 在C 中解析二进制消息.任何有示例的lib
- dllimport将一个c++方法移植到c#.当从C#调用时,程序关闭,没有任何错误消息
- 是否有任何方法可以将 Dbgprint () 消息存储到文件中
- 程序崩溃并显示消息"terminate called recursively"而不引发任何异常
- make find_package(OpenGL REQUIRED)失败,没有任何错误消息
- ICMPv6 -不能读取任何路由器通告消息
- c++ Windows没有得到任何消息
- 消息传递系统:回调可以是任何东西