| | |
| | | #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) |
| | | { |
| | |
| | | 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"); |
| | |
| | | } |
| | | |
| | | int |
| | | server() |
| | | server(const char *url) |
| | | { |
| | | nng_socket sock; |
| | | int rv; |
| | |
| | | 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 (;;) { |
| | |
| | | pthread_t tid; |
| | | pthread_create(&tid, NULL, client, NULL); |
| | | |
| | | server(); |
| | | server(config.get("client_url").c_str()); |
| | | return 0; |
| | | |
| | | } |