ZMQ_DEALER 模型
该模型是对请求响应套接字的扩展, 每个消息的发送是通过轮询调度算法去实现. 其 send和 recv 是不受限制 的
example:
server:
// ZMQ_DECLARE_SERVER.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
extern "C"{
#include
}
#pragma comment(lib,"libzmq_d.lib")
int _tmain(int argc, _TCHAR* argv[])
{
void* ctx = zmq_ctx_new();
void* server = zmq_socket(ctx, ZMQ_DEALER);
zmq_bind(server, "tcp://*:5050");
char* buffer[1024] = {0};
char* str = "我是服务器...";
while (true)
{
zmq_recv(server,buffer,1023,0);
printf("server: %s\n", buffer);
zmq_send(server, str, strlen(str), 0);
}
return 0;
}
client:
// ZMQ_DECLARE_SERVER.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
extern "C"{
#include
}
#pragma comment(lib,"libzmq_d.lib")
int _tmain(int argc, _TCHAR* argv[])
{
void* ctx = zmq_ctx_new();
void* server = zmq_socket(ctx, ZMQ_DEALER);
zmq_connect(server, "tcp://127.0.0.1:5050");
char* buffer[1024] = { 0 };
char* str = "我是客户端...1";
while (true)
{
zmq_send(server, str, strlen(str), 0);
zmq_recv(server, buffer, 1023, 0);
printf("server: %s\n", buffer);
}
return 0;
}