免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3548 | 回复: 3
打印 上一主题 下一主题

[C++] ZMQ ZMQ_STREAM 遇到问题不解。求指点 socket 通讯 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-12-23 14:26 |只看该作者 |倒序浏览
  1. void* context = zmq_ctx_new ();
  2.         void* socket = zmq_socket (context, ZMQ_STREAM);

  3.     int rc = zmq_connect (socket, "tcp://192.168.4.186:5000");
  4.     assert(rc == 0);

  5.         int sn = zmq_send(socket,szBufLoginSH,iBufLoginLenSH+1,ZMQ_DONTWAIT);
复制代码


用zmq 给server 端发消息,对方非zmq .    connect 正常server 发送消息client 能收到, 但是client 发送server 死活收不到,但是发送函数返回值还是正确的。   


不太懂。。

论坛徽章:
0
2 [报告]
发表于 2016-12-23 15:56 |只看该作者
显然要配套才行

论坛徽章:
0
3 [报告]
发表于 2016-12-24 17:14 |只看该作者
uint8_t id[256];  
    size_t id_size;
rc = zmq_getsockopt(socket, ZMQ_IDENTITY, id, &id_size);
   
    zmq_send(socket, id, id_size, ZMQ_DONTWAIT);
    int sn = zmq_send(socket,sndbuf,nLen,ZMQ_DONTWAIT);

ZMQ_STREAM

A socket of type ZMQ_STREAM is used to send and receive TCP data from a non-ØMQ peer, when using the tcp:// transport. A ZMQ_STREAM socket can act as client and/or server, sending and/or receiving TCP data asynchronously.

When receiving TCP data, a ZMQ_STREAM socket shall prepend a message part containing the identity of the originating peer to the message before passing it to the application. Messages received are fair-queued from among all connected peers.

When sending TCP data, a ZMQ_STREAM socket shall remove the first part of the message and use it to determine the identity of the peer the message shall be routed to, and unroutable messages shall cause an EHOSTUNREACH or EAGAIN error.

To open a connection to a server, use the zmq_connect call, and then fetch the socket identity using the ZMQ_IDENTITY zmq_getsockopt call.

To close a specific client connection, as a server, send the identity frame followed by a zero-length message (see EXAMPLE section).

论坛徽章:
0
4 [报告]
发表于 2016-12-24 17:16 |只看该作者
你上面这样发送才可以, send 数据之前先要send identity 一次。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP