예제 #1
0
파일: vtx_test.c 프로젝트: nexagames/vtx
static void
client_thread (void *args, zctx_t *ctx, void *pipe)
{
    //  Initialize virtual transport interface
    vtx_t *vtx = vtx_new (ctx);
    int rc = vtx_register (vtx, "udp", vtx_udp_driver);
    assert (rc == 0);

    //  Create client socket and connect to broadcast address
    void *client = vtx_socket (vtx, ZMQ_REQ);
    rc = vtx_connect (vtx, client, "udp://127.0.0.255:32000");
    assert (rc == 0);

    while (TRUE) {
        //  Look for name server anywhere on LAN
        zstr_send (client, "hello?");
        puts ("hello?");

        //  Wait for at most 1000msec for reply before retrying
        zmq_pollitem_t items [] = { { client, 0, ZMQ_POLLIN, 0 } };
        int rc = zmq_poll (items, 1, 1000 * ZMQ_POLL_MSEC);
        if (rc == -1)
            break;              //  Context has been shut down

        if (items [0].revents & ZMQ_POLLIN) {
            char *input = zstr_recv (client);
            puts (input);
            free (input);
            sleep (1);
        }
    }
    vtx_destroy (&vtx);
}
예제 #2
0
파일: vtx_test.c 프로젝트: nexagames/vtx
static void
server_thread (void *args, zctx_t *ctx, void *pipe)
{
    //  Initialize virtual transport interface
    vtx_t *vtx = vtx_new (ctx);
    int rc = vtx_register (vtx, "udp", vtx_udp_driver);
    assert (rc == 0);

    //  Create server socket and bind to all network interfaces
    void *server = vtx_socket (vtx, ZMQ_REP);
    rc = vtx_bind (vtx, server, "udp://*:32000");
    assert (rc == 0);

    while (TRUE) {
        char *input = zstr_recv (server);
        if (!input)
            break;              //  Interrupted
        puts (input);
        free (input);
        zstr_send (server, "ack");
    }
    vtx_destroy (&vtx);
}
예제 #3
0
파일: vtx_tcp.c 프로젝트: imatix/vtx
int vtx_tcp_load (vtx_t *vtx, Bool verbose)
{
    return vtx_register (vtx, VTX_TCP_SCHEME, vtx_tcp_driver, verbose);
}