-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.cpp
76 lines (60 loc) · 1.41 KB
/
server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*************************************************************************
> File Name: server.cpp
> Author:
> Mail:
> Created Time: 2017年05月07日 星期日 10时08分05秒
************************************************************************/
#include<iostream>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<assert.h>
#include<zmq.h>
#include<time.h>
using namespace std;
int main()
{
void *pCtx = NULL;
void *pSock = NULL;
const char * pAddr = "tcp://*:7766";
if((pCtx = zmq_ctx_new()) == NULL)
{
return 0;
}
if((pSock = zmq_socket(pCtx, ZMQ_DEALER)) == NULL)
{
zmq_ctx_destroy(pCtx);
return 0;
}
int iRvcTimeOut = 5000;
if(zmq_setsockopt(pSock, ZMQ_RCVTIMEO, &iRvcTimeOut, sizeof(iRvcTimeOut)) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
return 0;
}
if(zmq_bind(pSock, pAddr) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
return 0;
}
std::cout<<"receive"<<std::endl;
int i = 0;
while(1)
{
auto begin = time(NULL);
char buffer[1024 * 1024];
if(zmq_recv(pSock, buffer, sizeof(buffer), 0) < 0)
{
std::cout<<zmq_strerror(errno);
continue;
}
else
{
std::cout << buffer << std::endl;
}
auto end = time(NULL);
}
return 0;
}