Example #1
0
int main (int argc, char *argv [])
{
    int verbose = (argc > 1 && streq (argv [1], "-v"));
    mdcli_t *session = mdcli_new ("tcp://localhost:5555", verbose);
	zmsg_t *request;
	zmsg_t *reply;
    int count;

    //for (count = 0; count < 1; count++) {
        request = zmsg_new ();
        zmsg_pushstr (request, "KILL");
        reply = mdcli_send (session, "echo", &request);
        if (reply)
		{
			zframe_t * lastFrame = zmsg_last(reply);
			char* msg = zframe_strdup(lastFrame);
			printf("msg:%s\n", msg);
			printf("size:%d\n", zmsg_content_size(reply));
			//zframe_print(lastFrame,"->");
			zmsg_destroy (&reply);
		}
        //else
        //    break;              //  Interrupt or failure
    //}
    //printf ("%d requests/replies processed\n", count);
    mdcli_destroy (&session);
    return 0;
}
Example #2
0
int main (void)
{
    mdcli_t *mdcli;
    int rc;

    printf (" * mdcli: ");
    mdcli = mdcli_new ("tcp://127.0.0.1:5055");

    mdcli_destroy (&mdcli);
    return 0;

    return 0;
}
Example #3
0
int main (int argc, char *argv [])
{
    int verbose = (argc > 1 && streq (argv [1], "-v"));
    mdcli_t *session = mdcli_new ("tcp://localhost:5555", verbose);

    //  1. Send 'echo' request to Titanic
    zmsg_t *request = zmsg_new ();
    zmsg_addstr (request, "echo");
    zmsg_addstr (request, "Hello world");
    zmsg_t *reply = s_service_call (
        session, "titanic.request", &request);

    zframe_t *uuid = NULL;
    if (reply) {
        uuid = zmsg_pop (reply);
        zmsg_destroy (&reply);
        zframe_print (uuid, "I: request UUID ");
    }
    //  2. Wait until we get a reply
    while (!zctx_interrupted) {
        zclock_sleep (100);
        request = zmsg_new ();
        zmsg_add (request, zframe_dup (uuid));
        zmsg_t *reply = s_service_call (
            session, "titanic.reply", &request);

        if (reply) {
            char *reply_string = zframe_strdup (zmsg_last (reply));
            printf ("Reply: %s\n", reply_string);
            free (reply_string);
            zmsg_destroy (&reply);

            //  3. Close request
            request = zmsg_new ();
            zmsg_add (request, zframe_dup (uuid));
            reply = s_service_call (session, "titanic.close", &request);
            zmsg_destroy (&reply);
            break;
        }
        else {
            printf ("I: no reply yet, trying again...\n");
            zclock_sleep (5000);     //  Try again in 5 seconds
        }
    }
    zframe_destroy (&uuid);
    mdcli_destroy (&session);
    return 0;
}
Example #4
0
int main (int argc, char *argv [])
{
    int verbose = (argc > 1 && streq (argv [1], "-v"));
    mdcli_t *session = mdcli_new ("tcp://localhost:5555", verbose);

    //  1. Send 'echo' request to Titanic
    zmsg_t *request = zmsg_new ("Hello world");
    zmsg_push (request, "echo");
    zmsg_t *reply = s_service_call (
        session, "titanic.request", &request);
    char *uuid = NULL;
    if (reply) {
        uuid = zmsg_pop (reply);
        zmsg_destroy (&reply);
        printf ("I: request UUID: %s\n", uuid);
    }

    //  2. Wait until we get a reply
    while (!s_interrupted) {
        s_sleep (100);
        request = zmsg_new (uuid);
        zmsg_t *reply = s_service_call (
            session, "titanic.reply", &request);
        if (reply) {
            printf ("Reply: %s\n", zmsg_body (reply));
            zmsg_destroy (&reply);

            //  3. Close request
            request = zmsg_new (uuid);
            reply = s_service_call (session, "titanic.close", &request);
            zmsg_destroy (&reply);
            break;
        }
        else {
            printf ("I: no reply yet, trying again...\n");
            s_sleep (5000);     //  Try again in 5 seconds
        }
    }
    mdcli_destroy (&session);
    return 0;
}