Exemple #1
0
int main (void)
{
    puts ("Starting the zchat server");

    zsock_t *responder = zsock_new_rep ("tcp://*:5555");
    assert (responder);

    zsock_t *publisher = zsock_new_pub ("tcp://*:5556");
    assert (publisher);

    while (!zsys_interrupted) {
        //  Receive messages from client.
        char *client_msg = zstr_recv (responder);
        if (!client_msg)
            break;
        
        //  Let the zchat client know we got it.
        zstr_send (responder, "OK");

        //  Publish message to all zchat client subscribers
        zstr_send (publisher, client_msg);
        zstr_free (&client_msg);
    }

    puts ("Stopping the zchat server");

    zsock_destroy (&publisher);
    zsock_destroy (&responder);
    return 0;
}
JNIEXPORT jlong JNICALL
Java_org_zeromq_czmq_Zsock__1_1newRep (JNIEnv *env, jclass c, jstring endpoint)
{
    char *endpoint_ = (char *) (*env)->GetStringUTFChars (env, endpoint, NULL);
    jlong new_rep_ = (jlong) (intptr_t) zsock_new_rep (endpoint_);
    (*env)->ReleaseStringUTFChars (env, endpoint, endpoint_);
    return new_rep_;
}
MessageProcessor::MessageProcessor(ServerLoader& loader)
    : server_(loader.getServer())
    , zmqSocket_(zsock_new_rep(NULL))
    , zmqAuth_(zactor_new(zauth, NULL))
    , zmqPoller_(zpoller_new(zmqSocket_, NULL))
{
    init(loader.getPort(), loader.getTransportKey());
}
Exemple #4
0
void *hczmq(void *ptr) {
    struct host_connection hc;
    char port[6], timestamp[16], info[25];
    struct tm *tm;
    int idx;
    int rc;

    struct request req[1];
    zmsg_t *msg;

    printf("message from main thread: %s\n", (char *)ptr);

    // setup zmq server
    zsock_t *sock = zsock_new_rep(HCZMQ_SOCK);

    while(1) {
        // recv
        rc = get_request(sock, req);
        if (rc < 0) {
            // bad request
            continue;
        }
        strftime(timestamp, 16, "%Y%m%d%H%M%S", localtime(&req->timestamp));
        printf("ip: %s, timestamp: %s\n", INET_NTOA(req->ip), timestamp);

        // retrieve host connection by ip and timestamp
        pthread_mutex_lock(&mutex);
        msg = zmsg_new();
        for (idx = 0; idx < 3; idx++) {
            sprintf(port, "%d", ghc->conns[idx].port);
            tm = localtime(&ghc->conns[idx].timestamp);
            strftime(timestamp, 16, "%Y%m%d%H%M%S", tm);
            sprintf(info, "%s:%s", port, timestamp);
            printf("  %s\n", info);
            zmsg_addmem(msg, info, strlen(info));
        }
        pthread_mutex_unlock(&mutex);

        // send
        zmsg_send(&msg, sock);
    }

    pthread_exit((void*)123);
}
Exemple #5
0
///
//  Create a REP socket. Default action is bind.
QZsock* QZsock::newRep (const QString &endpoint, QObject *qObjParent)
{
    return new QZsock (zsock_new_rep (endpoint.toUtf8().data()), qObjParent);
}
Exemple #6
0
Z K1(zsocknewrep){R ptr(zsock_new_rep(xs));}
Exemple #7
0
static int pipe_loop_handler(zloop_t *loop, zsock_t *pipe, void *arg) {
    int ret = 0;
    client_proxy_t *self = arg;
    zmsg_t *request = zmsg_recv(pipe);
    if (!request) {
        return ret;
    }
    char *command = zmsg_popstr(request);
    if (self->verbose) {
        zsys_debug("client proxy: API command %s", command);
    }
    if (streq(command, "START")) {
        char *endpoint = zmsg_popstr(request);
        self->rep = zsock_new_rep(endpoint);
        assert(self->rep);
        zsys_info("client proxy: is listening on %s", endpoint);
        zloop_reader(self->loop, self->rep, reader_rep_event, self);
        zstr_free(&endpoint);

        char *pub_ep = zmsg_popstr(request);
        self->pub = zsock_new_pub(pub_ep);
        assert(self->pub);
        zsys_info("client proxy: is publishing on %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETTICKETSTORE")) {
        char *ep = zmsg_popstr(request);
        self->ticket_store_req = zsock_new_req(ep);
        assert(self->ticket_store_req);
        zsys_info("client proxy: ticket api using %s", ep);
        zstr_free(&ep);

        char *pub_ep = zmsg_popstr(request);
        self->ticket_store_sub = zsock_new_sub(pub_ep, "");
        zloop_reader(self->loop, self->ticket_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing messages from %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETPRINTERSTORE")) {
        char *ep = zmsg_popstr(request);
        self->printer_store_req = zsock_new_req(ep);
        assert(self->printer_store_req);
        zsys_info("client proxy: printer api is ready from %s", ep);
        zstr_free(&ep);

        char *subep = zmsg_popstr(request);
        self->printer_store_sub = zsock_new_sub(subep, "");
        zloop_reader(self->loop, self->printer_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing message from %s", subep);
        zstr_free(&subep);
        zsock_signal(self->pipe, 0);
    }
    else if (streq(command, "$TERM")) {
        ret = -1;
    } else if (streq(command, "VERBOSE")) {
        self->verbose = true;
    }
    zstr_free(&command);
    zmsg_destroy(&request);
    return ret;
}
Exemple #8
0
///
//  Create a REP socket. Default action is bind.
QmlZsock *QmlZsockAttached::constructRep (const QString &endpoint) {
    QmlZsock *qmlSelf = new QmlZsock ();
    qmlSelf->self = zsock_new_rep (endpoint.toUtf8().data());
    return qmlSelf;
};
Exemple #9
0
///
//  Create a REP socket. Default action is bind.
QmlZsock *QmlZsockAttached::newRep (const QString &endpoint) {
    QmlZsock *retQ_ = new QmlZsock ();
    retQ_->self = zsock_new_rep (endpoint.toUtf8().data());
    return retQ_;
};