PracticeDev/study_clang/zmq/zmq_experiment/value_client.c

52 lines
1.7 KiB
C

/*****************************************************************************
* Copyright: 2016-2026, Ieucd Tech. Co., Ltd.
* File name: client.c
* Description: 用于实现zmq多线程收发结构体消息的通信框架中的客户端部分。
* Author: TLSong
* Version: V0.0.1
* Date: 2020/7/7
* History:
* 2020/7/7 创建文件。
* *****************************************************************************/
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "data_mode.h"
int main (void)
{
printf ("Connecting to hello world server…\n");
void *context = zmq_ctx_new ();
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://127.0.0.1:5555");
int request_nbr;
for (request_nbr = 0; request_nbr < 3; request_nbr++) {
Msg recv_msg;
char send_ask[10] = "Random";
if(request_nbr==1)
strcpy(send_ask,"MAX");
else if(request_nbr==2)
strcpy(send_ask,"MIN");
char buffer [10];
printf ("Sending Hello %d…\n", request_nbr);
zmq_send (requester, send_ask, sizeof(send_ask), 0);
zmq_recv (requester, &recv_msg, sizeof(recv_msg), 0);
printf ("Reply received %d, content: \n", request_nbr);
printf ("---------------start---------------\n");
printf ("int: %d\n",recv_msg.Int);
printf ("char: %c\n",recv_msg.Char);
printf ("short: %hd\n",recv_msg.Short);
printf ("long: %ld\n",recv_msg.Long);
printf ("float: %d\n",recv_msg.Float);
printf ("double: %d\n",recv_msg.Double);
printf ("String: %s\n",recv_msg.String);
printf ("--------------- end ---------------\n");
}
zmq_close (requester);
zmq_ctx_destroy (context);
return 0;
}