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


Java ZContext.createSocket方法代码示例

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


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

示例1: ZMQProtobufClient

import org.zeromq.ZContext; //导入方法依赖的package包/类
ZMQProtobufClient(String zurl) {
	System.out.println("Starting zmq client to " + zurl);
	ctx = new ZContext();

	// We use ROUTER rather than DEALER because we want ZMQ to drop packets
	// (rather than blocking)
	// if we are not connected to the server.
	socket = ctx.createSocket(ZMQ.ROUTER);

	socket.setHWM(20);
	socket.setLinger(200); // in msecs

	// Use the following to get better client ids (must be unique)
	String identity = UUID.randomUUID().toString();
	socket.setIdentity(identity.getBytes(ZMQ.CHARSET));

	socket.connect(zurl);

	items = new PollItem[] { new PollItem(socket, Poller.POLLIN) };
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:21,代码来源:ZMQProtobufClient.java

示例2: main

import org.zeromq.ZContext; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main( String[] args )
{
	final ZContext ctx = new ZContext();
	final Socket client = ctx.createSocket( ZMQ.PAIR );
	//client.connect( "ipc:///tmp/zmqtest" );
	client.connect( "tcp://localhost:5556" );
	
	String msg = "";
	for ( int i = 0; i < 10; ++i )
	{
		client.send( "Hello " + i );
	}
	
	client.send( "exit" );
	
	ctx.destroy();
}
 
开发者ID:saalfeldlab,项目名称:bigcat,代码行数:21,代码来源:ZmqTestClient.java

示例3: main

import org.zeromq.ZContext; //导入方法依赖的package包/类
/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		final ZContext ctx = new ZContext();
		final Socket server = ctx.createSocket( ZMQ.PAIR );
		server.bind( "ipc:///tmp/zmqtest" );
//		server.bind( "tcp://*:5556" );
		System.out.println( "bind complete" );

		String msg = "";
		while ( !msg.equals( "exit" ) )
		{
			msg = server.recvStr();
			System.out.println( msg );
		}

		ctx.destroy();
	}
 
开发者ID:saalfeldlab,项目名称:bigcat,代码行数:21,代码来源:ZmqTestServer.java

示例4: run

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

       frontend = ctx.createSocket(ZMQ.ROUTER);
       frontend.bind("tcp://*:5570");

       backend = ctx.createSocket(ZMQ.DEALER);
       backend.bind("inproc://backend");

       //  Launch pool of worker threads, precise number is not critical
       for (int threadNbr = 0; threadNbr < 2; threadNbr++) {
           new Thread(new JeroMQServerWorker(ctx)).start();
       }

       //  Connect backend to frontend via a proxy
       ZMQ.proxy(frontend, backend, null);


}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:21,代码来源:JeroMQServerThread.java

示例5: run

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

	context = new ZContext();
	clientSocket = context.createSocket(ZMQ.PAIR);
	
	try {
		
		clientSocket.bind("tcp://*:" + incomingPort);
		logger.info("ComputationalServer UP");

		while (!Thread.currentThread().isInterrupted())
			receiveRequest();

	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		context.destroy();
		logger.info("ComputationalServer DOWN");
	}

}
 
开发者ID:enricobacis,项目名称:storm-joiner,代码行数:23,代码来源:ComputationalServer.java

示例6: handShake

import org.zeromq.ZContext; //导入方法依赖的package包/类
public void handShake() throws Exception {
	
	context = new ZContext();
	Socket server = context.createSocket(ZMQ.REQ);
	server.connect(connectionString);
	
	server.send(request.toMsg());
	String reply = new String(server.recv());
	context.destroy();
	
	if (reply.startsWith("ERROR"))
		throw new Exception(reply);
	
	String[] parts = reply.split(" ");
	port = Integer.parseInt(parts[0]);
	recordsHint = Integer.parseInt(parts[1]);
}
 
开发者ID:enricobacis,项目名称:storm-joiner,代码行数:18,代码来源:DataServerConnector.java

示例7: tryRequest

import org.zeromq.ZContext; //导入方法依赖的package包/类
private static ZMsg tryRequest (ZContext ctx, String endpoint, ZMsg request)
{
    System.out.printf("I: trying echo service at %s...\n", endpoint);
    Socket client = ctx.createSocket(ZMQ.REQ);
    client.connect(endpoint);

    //  Send request, wait safely for reply
    ZMsg msg = request.duplicate();
    msg.send(client);
    PollItem[] items = { new PollItem(client, ZMQ.Poller.POLLIN) };
    ZMQ.poll(items, REQUEST_TIMEOUT);
    ZMsg reply = null;
    if (items[0].isReadable())
        reply = ZMsg.recvMsg(client);

    //  Close socket in any case, we're done with it now
    ctx.destroySocket(client);
    return reply;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:flclient1.java

示例8: main

import org.zeromq.ZContext; //导入方法依赖的package包/类
public static void main(String[] args)
{
    if (args.length < 1) {
        System.out.printf("I: syntax: flserver1 <endpoint>\n");
        System.exit(0);
    }
    ZContext ctx = new ZContext();
    Socket server = ctx.createSocket(ZMQ.REP);
    server.bind(args[0]);

    System.out.printf ("I: echo service is ready at %s\n", args[0]);
    while (true) {
        ZMsg msg = ZMsg.recvMsg(server);
        if (msg == null)
            break;          //  Interrupted
        msg.send(server);
    }
    if (Thread.currentThread().isInterrupted())
        System.out.printf ("W: interrupted\n");

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

示例9: run

import org.zeromq.ZContext; //导入方法依赖的package包/类
public void run()
{
    ZContext context = new ZContext();
    //  Prepare our context and sockets
    Socket worker = context.createSocket(ZMQ.REQ);

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

    ZFrame frame = new ZFrame(lruqueue3.LRU_READY);
    //  Tell backend we're ready for work
    frame.send(worker, 0);

    while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null)
            break;

        msg.getLast().reset("OK".getBytes(ZMQ.CHARSET));

        msg.send(worker);
        System.out.println(Thread.currentThread().getName() + " Worker Sent OK");
    }

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

示例10: run

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

    //  Frontend socket talks to clients over TCP
    Socket frontend = ctx.createSocket(ZMQ.ROUTER);
    frontend.bind("tcp://*:5570");

    //  Backend socket talks to workers over inproc
    Socket backend = ctx.createSocket(ZMQ.DEALER);
    backend.bind("inproc://backend");

    //  Launch pool of worker threads, precise number is not critical
    for (int threadNbr = 0; threadNbr < 5; threadNbr++)
        new Thread(new server_worker(ctx)).start();

    //  Connect backend to frontend via a proxy
    ZMQ.proxy(frontend, backend, null);

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

示例11: run

import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run (Object ... args)
{
    ZContext context = new ZContext();

    //  Prepare our context and sockets
    Socket client  = context.createSocket (ZMQ.REQ);
    ZHelper.setId (client);     //  Set a printable identity

    client.connect("ipc://frontend.ipc");

    //  Send request, get reply
    client.send("HELLO");
    String reply = client.recvStr ();
    System.out.println("Client: " + reply);

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

示例12: run

import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run(Object[] args, ZContext ctx, Socket pipe)
{
    //  Subscribe to everything
    Socket subscriber = ctx.createSocket(ZMQ.SUB);
    subscriber.subscribe(ZMQ.SUBSCRIPTION_ALL);
    subscriber.connect("tcp://localhost:5556");

    //  Get and process messages
    while (true) {
        String string = subscriber.recvStr();
        System.out.printf("%s\n", string);
        long clock = Long.parseLong(string);

        //  Suicide snail logic
        if (System.currentTimeMillis() - clock > MAX_ALLOWED_DELAY) {
            System.err.println("E: subscriber cannot keep up, aborting");
            break;
        }
        //  Work for 1 msec plus some random additional time
        try {
            Thread.sleep(1000 + rand.nextInt(2000));
        } catch (InterruptedException e) {
            break;
        }
    }
    pipe.send("gone and died");
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:29,代码来源:suisnail.java

示例13: run

import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run()
{
    ZContext ctx = new ZContext();
    Socket worker = ctx.createSocket(ZMQ.REQ);
    worker.connect(String.format("ipc://%s-localbe.ipc", self));

    //  Tell broker we're ready for work
    ZFrame frame = new ZFrame(WORKER_READY);
    frame.send(worker, 0);

    while (true) {
        //  Send request, get reply
        ZMsg msg = ZMsg.recvMsg(worker, 0);
        if (msg == null)
            break;              //  Interrupted
        msg.getLast().print("Worker: ");
        msg.getLast().reset("OK");
        msg.send(worker);

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

示例14: run

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

    //  Frontend socket talks to clients over TCP
    Socket frontend = ctx.createSocket(ZMQ.ROUTER);
    frontend.bind("tcp://*:5570");

    //  Backend socket talks to workers over inproc
    Socket backend = ctx.createSocket(ZMQ.DEALER);
    backend.bind("inproc://backend");

    //  Launch pool of worker threads, precise number is not critical
    for (int threadNbr = 0; threadNbr < requestHanlderPoolSize; threadNbr++) {
        try {
            new Thread(new server_worker(ctx)).start();
        } catch (Exception e) {
            // Does nothing as a warning was already issued.
        }
    }

    //  Connect backend to frontend via a proxy
    ZMQ.proxy(frontend, backend, null);

    LOG.info("ZMQNBIServerPool - Exiting MAIN server thread");
    frontend.unbind("tcp://*:5570");
    backend.unbind("inproc://backend");
    ctx.destroySocket(frontend);
    ctx.destroySocket(backend);
    ctx.destroy();
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:32,代码来源:ZMQNBIServerPool.java

示例15: main

import org.zeromq.ZContext; //导入方法依赖的package包/类
/**
 * This method starts the server
 * 
 * @param args [hostname:port, properties_filename]
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

	// you might want to use a recommender
	Object recommender = null;

	String hostname = "0.0.0.0";
	int port = 8081;
	try {
		hostname = args[0].substring(0, args[0].indexOf(":"));
		port = Integer.parseInt(args[0].substring(args[0].indexOf(":") + 1));
	} catch (Exception e) {
		System.out.println("No hostname and port given. Using default 0.0.0.0:8081");
		logger.info(e.getMessage());
	}
	
	// initialize zeroMQ
	// initialize the 0MQ
	ZContext context = new ZContext();
	ZMQ.Socket clientSocket = context.createSocket(ZMQ.SUB);
	String serverURL = "tcp://" + hostname + ":" + port;
	if (serverURL == null) {
		serverURL = "tcp://127.0.0.1:8088";
	}
	clientSocket.bind(serverURL);
	
	// create the handler 
	ClientAndContestHandler0MQ me = new ClientAndContestHandler0MQ();
	for(;;) {
		String message = clientSocket.recvStr();
		// split the message
		String[] token = message.split("\t");

		// call handle and provide the relevant token
		String result = me.handle(token[0], null, token[3], token[4]);
		
		// send back the result
		clientSocket.send(result);			
	}
}
 
开发者ID:jasjisdo,项目名称:spark-newsreel-recommender,代码行数:46,代码来源:ClientAndContestHandler0MQ.java


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