Server

The server should handle incoming JSON-RPC requests on port 5000.

Install dependencies

Install the czmq library.

Write server script

Create a server.c:

#include <czmq.h>

int main(void) {
    // Connect
    zsock_t *responder = zsock_new_rep("tcp://*:5000");
    // Recv
    char *string = zstr_recv(responder);
    puts(string);
    zstr_free(&string);
    // Send
    zstr_send(responder, "Pong");
    // Disconnect
    zsock_destroy(&responder);
    return 0;
}

Build and start the server

$ gcc -lczmq server.c -o server
$ ./server

Client

Write client script

#include <czmq.h>

int main(void) {
    // Connect
    zsock_t *requester = zsock_new_req("tcp://127.0.0.1:5000");
    // Send
    zstr_send(requester, "Ping");
    // Recv
    char *string = zstr_recv(requester);
    puts(string);
    zstr_free(&string);
    // Disconnect
    zsock_destroy(&requester);
    return 0;
}

Build and run

$ gcc -lczmq client.c -o client
$ ./client
Pong