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


Java Socket.sendMore方法代码示例

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


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

示例1: main

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

    publisher.bind("tcp://*:5563");
    while (!Thread.currentThread ().isInterrupted ()) {
        // Write two messages, each with an envelope and content
        publisher.sendMore ("A");
        publisher.send ("We don't want to see this");
        publisher.sendMore ("B");
        publisher.send("We would like to see this");
    }
    publisher.close ();
    context.term ();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:17,代码来源:psenvpub.java

示例2: send

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
protected void send(final Message message, final Socket zmqSocket) throws IOException
{
    message.getHeader().setSession(id);

    if (isNotBlank(userName))
    {
        message.getHeader().setUsername(userName);
    }

    final List<byte[]> frames = protocol.toFrames(message);
    final int framesSize = frames.size();

    for (int i = 0; i < framesSize; i++)
    {
        final boolean lastFrame = i == (framesSize - 1);

        final byte[] frame = frames.get(i);

        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Sending {}frame: {}", (lastFrame ? "last " : ""), new String(frame,
                Protocol.ENCODING));
        }

        if (lastFrame)
        {
            if (!zmqSocket.send(frame))
            {
                throw new IOException("Failed to send frame " + i + " of message: " + message);
            }
        }
        else
        {
            if (!zmqSocket.sendMore(frame))
            {
                throw new IOException("Failed to send frame " + i + " of message: " + message);
            }
        }
    }
}
 
开发者ID:openanalytics,项目名称:japyter,代码行数:41,代码来源:Session.java

示例3: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run() {

    Context context = ZMQ.context(1);
    Socket worker = context.socket(ZMQ.DEALER);
    ZHelper.setId (worker);  //  Set a printable identity

    worker.connect("tcp://localhost:5671");

    int total = 0;
    while (true) {
        //  Tell the broker we're ready for work
        worker.sendMore ("");
        worker.send ("Hi Boss");

        //  Get workload from broker, until finished
        worker.recvStr ();   //  Envelope delimiter
        String workload = worker.recvStr ();
        boolean finished = workload.equals ("Fired!");
        if (finished) {
            System.out.printf ("Completed: %d tasks\n", total);
            break;
        }
        total++;

        //  Do some random work
        try {
            Thread.sleep (rand.nextInt (500) + 1);
        } catch (InterruptedException e) {
        }
    }
    worker.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:35,代码来源:rtdealer.java

示例4: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * While this example runs in a single process, that is just to make
 * it easier to start and stop the example. Each thread has its own
 * context and conceptually acts as a separate process.
 */
public static void main (String[] args) throws Exception {
    Context context = ZMQ.context(1);
    Socket broker = context.socket(ZMQ.ROUTER);
    broker.bind("tcp://*:5671");

    for (int workerNbr = 0; workerNbr < NBR_WORKERS; workerNbr++)
    {
        Thread worker = new Worker ();
        worker.start ();
    }

    //  Run for five seconds and then tell workers to end
    long endTime = System.currentTimeMillis () + 5000;
    int workersFired = 0;
    while (true) {
        //  Next message gives us least recently used worker
        String identity = broker.recvStr ();
        broker.sendMore (identity);
        broker.recv (0);     //  Envelope delimiter
        broker.recv (0);     //  Response from worker
        broker.sendMore ("");

        //  Encourage workers until it's time to fire them
        if (System.currentTimeMillis () < endTime)
            broker.send ("Work harder");
        else {
            broker.send ("Fired!");
            if (++workersFired == NBR_WORKERS)
                break;
        }
    }

    broker.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:41,代码来源:rtdealer.java

示例5: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public void run()
{
    Context context = ZMQ.context(1);
    //  Prepare our context and sockets
    Socket worker  = context.socket(ZMQ.REQ);
    ZHelper.setId (worker);     //  Set a printable identity

    worker.connect("ipc://backend.ipc");

    //  Tell backend we're ready for work
    worker.send("READY");

    while(!Thread.currentThread ().isInterrupted ())
    {
        String address = worker.recvStr ();
        String empty = worker.recvStr ();
        assert (empty.length() == 0);

        //  Get request, send reply
        String request = worker.recvStr ();
        System.out.println("Worker: " + request);

        worker.sendMore (address);
        worker.sendMore ("");
        worker.send("OK");
    }
    worker.close ();
    context.term ();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:30,代码来源:lbbroker.java

示例6: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * While this example runs in a single process, that is just to make
 * it easier to start and stop the example. Each thread has its own
 * context and conceptually acts as a separate process.
 */
public static void main (String[] args) throws Exception {
    Context context = ZMQ.context(1);
    Socket broker = context.socket(ZMQ.ROUTER);
    broker.bind("tcp://*:5671");

    for (int workerNbr = 0; workerNbr < NBR_WORKERS; workerNbr++)
    {
        Thread worker = new Worker ();
        worker.start ();
    }

    //  Run for five seconds and then tell workers to end
    long endTime = System.currentTimeMillis () + 5000;
    int workersFired = 0;
    while (true) {
        //  Next message gives us least recently used worker
        String identity = broker.recvStr ();
        broker.sendMore (identity);
        broker.recvStr ();     //  Envelope delimiter
        broker.recvStr ();     //  Response from worker
        broker.sendMore ("");

        //  Encourage workers until it's time to fire them
        if (System.currentTimeMillis () < endTime)
            broker.send ("Work harder");
        else {
            broker.send ("Fired!");
            if (++workersFired == NBR_WORKERS)
                break;
        }
    }

    broker.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:41,代码来源:rtreq.java


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