wangzhengquan
2020-06-19 1b26f1dd275e7ff947fcf2ecdbbad8f6bc1e0b49
service/test_client.c
@@ -1,12 +1,14 @@
#include "usg_common.h"
#include "netdisk.h"
#include "hcnetdisk.h"
#include "properties_config.h"
#include <jsoncpp/json/json.h>
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
const char *url = "tcp://127.0.0.1:8899";
const char *localUrl = "tcp://127.0.0.1:9988";
PropertiesConfig config("../data/config.txt");
void
fatal(const char *func, int rv)
{
@@ -152,7 +154,7 @@
   if ((rv = nng_req0_open(&sock)) != 0) {
      fatal("nng_socket", rv);
   }
   if ((rv = nng_dial(sock, url, NULL, 0)) != 0) {
   if ((rv = nng_dial(sock, config.get("server_url").c_str(), NULL, 0)) != 0) {
      fatal("nng_dial", rv);
   }
   //printf("CLIENT: SENDING DATE REQUEST\n");
@@ -187,7 +189,7 @@
}
int
server()
server(const char *url)
{
   nng_socket sock;
   int        rv;
@@ -195,7 +197,7 @@
   if ((rv = nng_rep0_open(&sock)) != 0) {
      fatal("nng_rep0_open", rv);
   }
   if ((rv = nng_listen(sock, localUrl, NULL, 0)) != 0) {
   if ((rv = nng_listen(sock, url, NULL, 0)) != 0) {
      fatal("nng_listen", rv);
   }
   for (;;) {
@@ -230,7 +232,7 @@
   pthread_t tid;
    pthread_create(&tid, NULL, client, NULL);
    
   server();
   server(config.get("client_url").c_str());
   return 0;
   
}