当前位置: 首页>>代码示例>>Java>>正文


Java Socket.setIdentity方法代码示例

本文整理汇总了Java中org.zeromq.ZMQ.Socket.setIdentity方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.setIdentity方法的具体用法?Java Socket.setIdentity怎么用?Java Socket.setIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.zeromq.ZMQ.Socket的用法示例。


在下文中一共展示了Socket.setIdentity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main (String[] args) throws InterruptedException {

        Context context = ZMQ.context(1);
        Socket sink = context.socket(ZMQ.ROUTER);
        sink.bind("inproc://example");

        //  First allow 0MQ to set the identity, [00] + random 4byte
        Socket anonymous = context.socket(ZMQ.REQ);

        anonymous.connect("inproc://example");
        anonymous.send ("ROUTER uses a generated UUID",0);
        ZHelper.dump (sink);

        //  Then set the identity ourself
        Socket identified = context.socket(ZMQ.REQ);
        identified.setIdentity("Hello".getBytes (ZMQ.CHARSET));
        identified.connect ("inproc://example");
        identified.send("ROUTER socket uses REQ's socket identity", 0);
        ZHelper.dump (sink);

        sink.close ();
        anonymous.close ();
        identified.close();
        context.term();

    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:identity.java

示例2: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public void run() {
    ZContext ctx = new ZContext();
    Socket client = ctx.createSocket(ZMQ.DEALER);

    //  Set random identity to make tracing easier
    String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
    client.setIdentity(identity.getBytes(ZMQ.CHARSET));
    client.connect("tcp://localhost:5570");

    PollItem[] items = new PollItem[] { new PollItem(client, Poller.POLLIN) };

    int requestNbr = 0;
    while (!Thread.currentThread().isInterrupted()) {
        //  Tick once per second, pulling in arriving messages
        for (int centitick = 0; centitick < 100; centitick++) {
            ZMQ.poll(items, 10);
            if (items[0].isReadable()) {
                ZMsg msg = ZMsg.recvMsg(client);
                msg.getLast().print(identity);
                msg.destroy();
            }
        }
        client.send(String.format("request #%d", ++requestNbr), 0);
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:asyncsrv.java

示例3: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    ZContext ctx = new ZContext();
    Socket worker = ctx.createSocket(ZMQ.REQ);

    //  Set random identity to make tracing easier
    Random rand = new Random(System.nanoTime());
    String identity = String.format("%04X-%04X", rand.nextInt(0x10000), rand.nextInt(0x10000));
    worker.setIdentity(identity.getBytes(ZMQ.CHARSET));
    worker.connect("tcp://localhost:5556");

    //  Tell broker we're ready for work
    System.out.printf("I: (%s) worker ready\n", identity);
    ZFrame frame = new ZFrame(WORKER_READY);
    frame.send(worker, 0);

    int cycles = 0;
    while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null)
            break;              //  Interrupted

        //  Simulate various problems, after a few cycles
        cycles++;
        if (cycles > 3 && rand.nextInt(5) == 0) {
            System.out.printf("I: (%s) simulating a crash\n", identity);
            msg.destroy();
            break;
        } else if (cycles > 3 && rand.nextInt(5) == 0) {
            System.out.printf("I: (%s) simulating CPU overload\n", identity);
            Thread.sleep(3000);
        }
        System.out.printf("I: (%s) normal reply\n", identity);
        Thread.sleep(1000); //  Do some heavy work
        msg.send(worker);
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:39,代码来源:spworker.java

示例4: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run() {
    ZContext ctx = new ZContext();
    Socket worker = ctx.createSocket(ZMQ.DEALER);
    worker.setHWM (0);
    worker.setIdentity("W".getBytes(ZMQ.CHARSET));
    worker.connect("tcp://localhost:5556");
    while (!Thread.currentThread().isInterrupted()) {
        ZMsg msg = ZMsg.recvMsg(worker);
        msg.send(worker);
    }

    ctx.destroy();

}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:16,代码来源:tripping.java

示例5: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main(String[] args)
{
    Context context = ZMQ.context(1);

    Socket client = context.socket(ZMQ.ROUTER);
    client.bind("ipc://routing.ipc");

    Socket worker = context.socket(ZMQ.REP);
    worker.setIdentity("A".getBytes(ZMQ.CHARSET));
    worker.connect("ipc://routing.ipc");

    //  Wait for the worker to connect so that when we send a message
    //  with routing envelope, it will actually match the worker
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    //  Send papa address, address stack, empty part, and request
    client.send("A", ZMQ.SNDMORE);
    client.send("address 3", ZMQ.SNDMORE);
    client.send("address 2", ZMQ.SNDMORE);
    client.send("address 1", ZMQ.SNDMORE);
    client.send("", ZMQ.SNDMORE);
    client.send("This is the workload", 0);

    //  Worker should get just the workload
    ZHelper.dump(worker);

    //  We don't play with envelopes in the worker
    worker.send("This is the reply", 0);

    //  Now dump what we got off the ROUTER socket
    ZHelper.dump(client);

    client.close();
    worker.close();
    context.term();

}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:42,代码来源:rtpapa.java

示例6: setId

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void setId (Socket sock)
{
    String identity = String.format ("%04X-%04X", rand.nextInt (), rand.nextInt ());

    sock.setIdentity (identity.getBytes (ZMQ.CHARSET));
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:7,代码来源:ZHelper.java

示例7: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main(String[] args)
{
    boolean verbose = (args.length > 0 && args[0].equals("-v"));

    ZContext ctx = new ZContext();
    //  Prepare server socket with predictable identity
    String bindEndpoint = "tcp://*:5555";
    String connectEndpoint = "tcp://localhost:5555";
    Socket server = ctx.createSocket(ZMQ.ROUTER);
    server.setIdentity(connectEndpoint.getBytes(ZMQ.CHARSET));
    server.bind(bindEndpoint);
    System.out.printf ("I: service is ready at %s\n", bindEndpoint);

    while (!Thread.currentThread().isInterrupted()) {
        ZMsg request = ZMsg.recvMsg(server);
        if (verbose && request != null)
            request.dump(System.out);

        if (request == null)
            break;          //  Interrupted

        //  Frame 0: identity of client
        //  Frame 1: PING, or client control frame
        //  Frame 2: request body
        ZFrame identity = request.pop();
        ZFrame control = request.pop();
        ZMsg reply = new ZMsg();
        if (control.equals("PING"))
            reply.add("PONG");
        else {
            reply.add(control);
            reply.add("OK");
        }
        request.destroy();
        reply.push(identity);
        if (verbose && reply != null)
            reply.dump(System.out);
        reply.send(server);
    }
    if (Thread.currentThread().isInterrupted())
        System.out.printf ("W: interrupted\n");

    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:45,代码来源:flserver3.java


注:本文中的org.zeromq.ZMQ.Socket.setIdentity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。