zmq_device test

/************************************************************************* 
    > File Name: test.cpp 
    > Author: wangzhicheng 
    > Mail: 2363702560@qq.com  
    > Created Time:2017-02-13
 ************************************************************************/  
#include <iostream>  
#include <vector>  
#include <thread>  
#include <chrono>  
#include "ZMQ_PipeSocket.h"
using namespace zmqpipe;
static const string ADDR0 = "tcp://127.0.0.1:8888";
static const chrono::milliseconds dura(1000);  // 1s
void client_thread()
{
	string str;
	ZMQ_PIPESocket sender;
	if(!sender.Init(ZMQ_REQ, ADDR0))
	{
		cerr << "client init failed...!" << endl;
		exit(EXIT_FAILURE);
	}
	while(1)
	{
		if(!sender.Send("Hello World...!"))
		{
			cerr << "client send failed...!" << endl;
		}
		if(!sender.Recv(str))
		{
			cerr << "client recv failed...!" << endl;
		}
		else 
		{
			cout << "client recv = " << str << endl;
		}
		this_thread::sleep_for(dura);
	}
}
int main()  
{  
	thread th_client(client_thread);
	th_client.join();

    return 0;  
}  

/************************************************************************* 
    > File Name: test.cpp 
    > Author: wangzhicheng 
    > Mail: 2363702560@qq.com  
    > Created Time:2017-02-13
 ************************************************************************/  
#include <iostream>  
#include <vector>  
#include <thread>  
#include <chrono>  
#include "ZMQ_PipeSocket.h"
using namespace zmqpipe;
static const string ADDR = "ipc://127.0.0.1.ipc";
//static const string ADDR = "tcp://127.0.0.1:9999";
static const chrono::milliseconds dura(1000);  // 1s
void server_thread()
{
	string str;
	ZMQ_PIPESocket receiver;
	if(!receiver.Init(ZMQ_REP, ADDR))
	{
		cerr << "server init failed...!" << endl;
		exit(EXIT_FAILURE);
	}
	while(1)
	{
		if(!receiver.Recv(str))
		{
			cerr << "server recv failed...!" << endl;
		}
		else cout << "server recv = " << str << endl;
		if(!receiver.Send(str))
		{
			cerr << "server send failed...!" << endl;
		}
		this_thread::sleep_for(dura);
	}
}
int main()  
{  
	static const int N = 1;
	vector<thread>worker_threads;
	for(int i = 0;i < N;i++)
	{
		worker_threads.emplace_back(thread(server_thread));
	}
	for(auto &th:worker_threads) 
	{
		th.join();
	}

    return 0;  
}  


/************************************************************************* 
    > File Name: test.cpp 
    > Author: wangzhicheng 
    > Mail: 2363702560@qq.com  
    > Created Time:2017-02-13
 ************************************************************************/  
#include <iostream>  
#include <vector>  
#include <thread>  
#include <chrono>  
#include "ZMQ_PipeSocket.h"
using namespace zmqpipe;
static const string ADDR0 = "tcp://*:8888";
static const string ADDR1 = "ipc://127.0.0.1.ipc";
//static const string ADDR1 = "tcp://*:9999";
int main()  
{  
	ZMQ_PIPESocket clients;
	if(!clients.Init(ZMQ_ROUTER, ADDR0))
	{
		cerr << "client init failed...!" << endl;
		exit(EXIT_FAILURE);
	}
	ZMQ_PIPESocket workers;
	if(!workers.Init(ZMQ_DEALER, ADDR1))
	{
		cerr << "workers init failed...!" << endl;
		exit(EXIT_FAILURE);
	}
	zmq_device(ZMQ_QUEUE, clients.m_pSocket, workers.m_pSocket);
	cout << "ll" << endl;

    return 0;  
}  
/************************************************************************* 
 *      > File Name: ZMQ_PipeSocket.cpp 
 *      > Author: wangzhicheng 
 *      > Mail: 2363702560@qq.com 
 *      > Created Time: 2017-02-07
 *      > statement: ZMQ封装类 
 *************************************************************************/  
#include "ZMQ_PipeSocket.h"  
namespace zmqpipe  
{  
ZMQ_PIPESocket::ZMQ_PIPESocket()   
{  
    m_pContext = NULL;  
    m_pSocket = NULL;  
}  
bool ZMQ_PIPESocket::Init(int SocketType, 
						  const string &addr, 
						  int sendhwm, 
						  int recvhwm, 
						  int sendtimeout)   
{  
    m_pContext = zmq_ctx_new();  
    if(!m_pContext) return false;  
    m_pSocket = zmq_socket(m_pContext, SocketType);  
    if(!m_pSocket) return false;  
	int rc;
	switch(SocketType)
	{
	case ZMQ_PULL:
	case ZMQ_PUB:
	case ZMQ_ROUTER:
	case ZMQ_DEALER:
		rc = zmq_bind(this->m_pSocket, addr.c_str());
		break;
	case ZMQ_REP:
	case ZMQ_REQ:
	case ZMQ_PUSH:
	case ZMQ_SUB:
		rc = zmq_connect(this->m_pSocket, addr.c_str());
		break;
	default:
		return false;
	}
    rc = zmq_setsockopt(m_pSocket, ZMQ_SNDHWM, &sendhwm, sizeof(sendhwm));  
    if(rc) return false;  
    rc = zmq_setsockopt(m_pSocket, ZMQ_RCVHWM, &recvhwm, sizeof(recvhwm));  
    if(rc) return false;  
    rc = zmq_setsockopt(m_pSocket, ZMQ_SNDTIMEO, &sendtimeout, sizeof(sendtimeout));  
    if(rc) return false;  
    m_strSendServer = addr;  
  
    return true;  
}  
/* 
 * @brief 发送info指向的对象  
 * @len 对象的大小 字节数 
 * */  
bool ZMQ_PIPESocket::Send(void *info, int len)   
{  
    int rc;  
    zmq_msg_t msg;  
    rc = zmq_msg_init_size(&msg, len);  
    if(rc) return false;  
    memcpy(zmq_msg_data(&msg), (char *)info, len);  
    rc = zmq_msg_send(&msg, this->m_pSocket, 0);  
  
    return rc == len;  
}  
/* 
 * @brief 发送string对象  
 * */  
bool ZMQ_PIPESocket::Send(const string &strSend)   
{  
    int rc;  
    size_t len = strSend.size();  
    zmq_msg_t msg;  
    rc = zmq_msg_init_size(&msg, len);  
    if(rc) return false;  
    memcpy(zmq_msg_data(&msg), strSend.c_str(), len);  
    size_t Len = zmq_msg_send(&msg, this->m_pSocket, 0);  
  
    return Len == len;  
}  
/* 
 * @brief 接收数据 接收的数据由info指向 
 * */  
bool ZMQ_PIPESocket::Recv(void *info)   
{  
    int rc;  
    zmq_msg_t msg;  
    rc = zmq_msg_init(&msg);  
    if(rc) return false;  
    int len = zmq_msg_recv(&msg, this->m_pSocket, 0);    // 阻塞方式  
    if(len <= 0) return false;  
    memcpy(info, (char *)zmq_msg_data(&msg), len);  
    if(zmq_msg_close(&msg)) return false;  
  
    return true;  
}     
/* 
 * @brief 接收string对象数据 
 * */  
bool ZMQ_PIPESocket::Recv(string &strRecv)   
{  
    int rc;  
    zmq_msg_t msg;  
    rc = zmq_msg_init(&msg);  
    if(rc) return false;  
    int len = zmq_msg_recv(&msg, this->m_pSocket, 0);    // 阻塞方式  
    if(len <= 0) return false;  
    strRecv.assign((char *)zmq_msg_data(&msg), len);  
    if(zmq_msg_close(&msg)) return false;  
  
    return true;  
}     
/*
 * @brief recieving from a socket is over
 * */
bool ZMQ_PIPESocket::RecvOver()
{
	int64_t more;
	size_t more_size = sizeof(more);
	zmq_getsockopt(m_pSocket, ZMQ_RCVMORE, &more, &more_size);

	return more <= 0;
}
ZMQ_PIPESocket::~ZMQ_PIPESocket()   
{  
    if(m_pSocket)   
    {  
        zmq_close(m_pSocket);  
        m_pSocket = NULL;  
    }  
    if(m_pContext)   
    {  
        zmq_ctx_destroy(m_pContext);  
        m_pContext = NULL;  
    }  
}  
}  


[==========] Running 77 tests from 2 test suites. [----------] Global test environment set-up. [----------] 1 test from TestRHZmqCommunication [ RUN ] TestRHZmqCommunication.testCommunication 2025-08-15 15:04:17 794.824 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/include/test_rh_zmq_communication.h:TestRHZmqCommunication:32] [Construct Start...] 2025-08-15 15:04:17 794.992 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/entry/source/rh_entry.cpp:RHEntry:38] [Construct RHEntry ...] 2025-08-15 15:04:17 795.036 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/include/test_rh_zmq_communication.h:TestRHZmqCommunication:37] [Construct end...] 2025-08-15 15:04:17 795.068 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/include/test_rh_zmq_communication.h:SetUp:48] [ Set Up Start...] 2025-08-15 15:04:17 795.096 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/entry/source/rh_entry.cpp:RHEntry:38] [Construct RHEntry ...] yaml file not exist:/home/yaoyedong/rhc/mw_config.yaml 2025-08-15 15:04:17 795.491 [132287390417024] [ERROR] [/home/xuejibao/version_zmq/basiclibrary/bneyaml/src/bne_yaml.cpp:BNEYamlInit:59] [yaml file not exist: /home/yaoyedong/rhc/mw_config.yaml ] 2025-08-15 15:04:17 795.546 [132287390417024] [ERROR] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/zmq/src/rh_server.cpp:RHServerInit:65] [BNEYamlInit failed [ef000011]] 2025-08-15 15:04:17 795.581 [132287390417024] [ERROR] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/include/test_rh_zmq_communication.h:SetServerInitialize:82] [RHRegisterCallback ServerInit failed] 2025-08-15 15:04:17 795.627 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/mock/source/mock_rt_device_manager.cpp:~RTDeviceManager:99] [----test----device---destruct----] 2025-08-15 15:04:17 795.667 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/include/test_rh_zmq_communication.h:SetUp:52] [ Set Up End...] 2025-08-15 15:04:17 795.704 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/mock/source/mock_rt_device_manager.cpp:~RTDeviceManager:99] [----test----device---destruct----] [ OK ] TestRHZmqCommunication.testCommunication (0 ms) [----------] 1 test from TestRHZmqCommunication (0 ms total) [----------] 76 tests from TestBusinessStateMachine [ RUN ] TestBusinessStateMachine.testDoRobotGetFromSmif 2025-08-15 15:04:17 796.174 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/entry/source/rh_entry.cpp:RHEntry:38] [Construct RHEntry ...] 2025-08-15 15:04:17 796.251 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/entry/source/rh_entry.cpp:RHEntry:38] [Construct RHEntry ...] 2025-08-15 15:04:17 796.453 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/mock/source/mock_rt_device_manager.cpp:~RTDeviceManager:99] [----test----device---destruct----] 2025-08-15 15:04:17 796.580 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:DoRobotGetFromSmif:287] [State:RobotGetFromSmif,Substate:RH_INITIALIZE_SUBSTATE] 2025-08-15 15:04:17 796.760 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:DoRobotGetFromSmif:300] [Load Reticle: From Smif ...] 2025-08-15 15:04:17 796.814 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:AddState:2453] [RH: add state ,state:7, substate:16] 2025-08-15 15:04:17 796.853 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:AddState:2453] [RH: add state ,state:7, substate:22] 2025-08-15 15:04:17 796.890 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/robot_module.cpp:RobotGetFromSmif:161] [State:RobotGetFromSmif,Substate:RH_INITIALIZE_SUBSTATE] /home/yushijin/fromGitLib/myWorkspace/20250813/rhc/tests/unit_src/test_business_state_machine.cpp:158: Failure Actual function call count doesn't match EXPECT_CALL(*mockRobotModule_, RobotGetFromSmif(testing::_,testing::_))... Expected: to be called once Actual: never called - unsatisfied and active 2025-08-15 15:04:17 797.058 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:DoRobotGetFromSmif:287] [State:RobotGetFromSmif,Substate:RH_ROBOTT_MOVE_TO_HOMET_SUBSTATE] 2025-08-15 15:04:17 797.107 [132287390417024] [ERROR] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/business_state_machine.cpp:DoRobotGetFromSmif:349] [Smif Or Robot Material Error ...] 2025-08-15 15:04:17 797.143 [132287390417024] [DEBUG] [/home/yushijin/fromGitLib/myWorkspace/20250813/rhc/src/source/controller/source/robot_module.cpp:RobotGetFromSmif:161] [State:RobotGetFromSmif,Substate:RH_ROBOTT_MOVE_TO_HOMET_SUBSTATE] Segmentation fault (core dumped)
08-16
已完成(A) lqx@lqx:~/PyCharmMiscProject$ pip uninstall pyzmq -y Found existing installation: pyzmq 27.1.0 Uninstalling pyzmq-27.1.0: Successfully uninstalled pyzmq-27.1.0 (A) lqx@lqx:~/PyCharmMiscProject$ (A) lqx@lqx:~/PyCharmMiscProject$ sudo apt-get update [sudo] lqx 的密码: 命中:1 http://security.ubuntu.com/ubuntu focal-security InRelease 命中:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease 命中:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease 命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease 正在读取软件包列表... 完成 (A) lqx@lqx:~/PyCharmMiscProject$ sudo apt-get install libzmq3-dev 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 libzmq3-dev 已经是最新版 (4.3.2-2ubuntu1)。 升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 261 个软件包未被升级。 (A) lqx@lqx:~/PyCharmMiscProject$ pip install pyzmq --force-reinstall --no-binary pyzmq Collecting pyzmq Using cached pyzmq-27.1.0-cp38-cp38-linux_x86_64.whl Installing collected packages: pyzmq Successfully installed pyzmq-27.1.0 [notice] A new release of pip is available: 24.3.1 -> 25.0.1 [notice] To update, run: pip install --upgrade pip,仍存在/home/lqx/anaconda3/envs/A/bin/python /home/lqx/桌面/OpenCastKit-master/OpenCastKit-master/train_graphcast.py /home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/hfai/nn/modules/fast_multihead_attention.py:64: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead. @torch.cuda.amp.custom_fwd(cast_inputs=torch.float32) /home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/hfai/nn/modules/fast_multihead_attention.py:488: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead. def backward(ctx, grad_output2, grad_weight): /home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/hfai/nn/modules/hf_norm.py:23: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead. @torch.cuda.amp.custom_fwd(cast_inputs=torch.float32) /home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/hfai/nn/modules/hf_norm.py:57: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead. def backward(ctx, dy): 非集群环境 Traceback (most recent call last): File "/home/lqx/桌面/OpenCastKit-master/OpenCastKit-master/train_graphcast.py", line 11, in <module> import hfai.nccl.distributed as dist File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/hfai/nccl/distributed/__init__.py", line 13, in <module> import zmq File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/__init__.py", line 52, in <module> from zmq import backend File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/backend/__init__.py", line 30, in <module> raise original_error from None File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/backend/__init__.py", line 25, in <module> _ns = select_backend(first) File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/backend/select.py", line 31, in select_backend mod = import_module(name) File "/home/lqx/anaconda3/envs/A/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/backend/cython/__init__.py", line 6, in <module> from . import _zmq File "/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages/zmq/backend/cython/_zmq.py", line 34, in <module> raise ImportError(msg) ImportError: Attempting to import zmq Cython backend, which has not been compiled. This probably means you are importing zmq from its source tree. if this is what you want, make sure to do an in-place build first: pip install -e '/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages' If it is not, then '/home/lqx/anaconda3/envs/A/lib/python3.8/site-packages' is probably on your sys.path, when it shouldn't be. Is that your current working directory? If neither of those is true and this file is actually installed, something seems to have gone wrong with the install! Please report at https://github.com/zeromq/pyzmq/issues 进程已结束,退出代码为 1
最新发布
12-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值