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


Java Socket.close方法代码示例

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


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

示例1: main

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

        // Prepare our context and subscriber
        Context context = ZMQ.context(1);
        Socket subscriber = context.socket(ZMQ.SUB);

        subscriber.connect("tcp://localhost:5563");
        subscriber.subscribe("B".getBytes(ZMQ.CHARSET));
        while (!Thread.currentThread ().isInterrupted ()) {
            // Read envelope with address
            String address = subscriber.recvStr ();
            // Read message contents
            String contents = subscriber.recvStr ();
            System.out.println(address + " : " + contents);
        }
        subscriber.close ();
        context.term ();
    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:19,代码来源:psenvsub.java

示例2: main

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

    //  This is where the weather server sits
    Socket frontend =  context.socket(ZMQ.SUB);
    frontend.connect("tcp://192.168.55.210:5556");

    //  This is our public endpoint for subscribers
    Socket backend  = context.socket(ZMQ.PUB);
    backend.bind("tcp://10.1.1.0:8100");

    //  Subscribe on everything
    frontend.subscribe(ZMQ.SUBSCRIPTION_ALL);

    //  Run the proxy until the user interrupts us
    ZMQ.proxy (frontend, backend, null);

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

示例3: sendAsync

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
private static void sendAsync(int val, String account) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5559");
    System.out.println("launch and connect client.");
    ValidateRequest req = new ValidateRequest(account, new BigDecimal(val));

    //send request
    requester.send(objectMapper.writeValueAsString(req), 0);
    //receive response
    String responseStr = requester.recvStr(0);

    //parse and print reply
    ValidateResponse reply = objectMapper.readValue(responseStr, ValidateResponse.class);
    System.out.println("Received reply for request= " + req + " reply= " + reply + "");

    //  We never get here but clean up anyhow
    requester.close();
    context.term();
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:24,代码来源:TestAsyncMicroServiceMain.java

示例4: main

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

    //  Socket facing clients
    Socket frontend = context.socket(ZMQ.ROUTER);
    frontend.bind("tcp://*:5559");

    //  Socket facing services
    Socket backend = context.socket(ZMQ.DEALER);
    backend.bind("tcp://*:5560");

    //  Start the proxy
    ZMQ.proxy (frontend, backend, null);

    //  We never get here but clean up anyhow
    frontend.close();
    backend.close();
    context.term();
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:21,代码来源:ZeroMQBroker.java

示例5: main

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

    //  Socket to talk to server
    Socket responder = context.socket (ZMQ.REP);
    responder.connect ("tcp://localhost:5560");

    while (!Thread.currentThread ().isInterrupted ()) {
        //  Wait for next request from client
        String string = responder.recvStr (0);
        System.out.printf ("Received request: [%s]\n", string);

        //  Do some 'work'
        Thread.sleep (1000);

        //  Send reply back to client
        responder.send ("World");
    }

    //  We never get here but clean up anyhow
    responder.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:24,代码来源:rrworker.java

示例6: main

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

    //  Socket to talk to server
    Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5559");
    
    System.out.println("launch and connect client.");

    for (int request_nbr = 0; request_nbr < 10; request_nbr++) {
        requester.send("Hello", 0);
        String reply = requester.recvStr (0);
        System.out.println("Received reply " + request_nbr + " [" + reply + "]");
    }
    
    //  We never get here but clean up anyhow
    requester.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:rrclient.java

示例7: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run() {
    int port;
    Socket frontend = ctx.socket(ZMQ.ROUTER);

    assertNotNull (frontend);
    port = frontend.bind ("tcp://127.0.0.1:6660");
    assertEquals (port, 6660);


    Socket backend = ctx.socket(ZMQ.DEALER);
    assertNotNull (backend);
    port = backend.bind ("tcp://127.0.0.1:6661");
    assertEquals (port, 6661);

    ZMQ.proxy (frontend, backend, null);

    frontend.close();
    backend.close();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:21,代码来源:TestProxy.java

示例8: run

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

    //  Prepare our context and sockets
    Socket client  = context.socket(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);

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

示例9: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run(){
    //  Bind to inproc: endpoint, then start upstream thread
    Socket receiver = context.socket(ZMQ.PAIR);
    receiver.bind("inproc://step2");
    Thread step1 = new Step1 (context);
    step1.start();

    //  Wait for signal
    receiver.recv(0);
    receiver.close ();

    //  Connect to step3 and tell it we're ready
    Socket xmitter = context.socket(ZMQ.PAIR);
    xmitter.connect("inproc://step3");
    xmitter.send("READY", 0);

    xmitter.close ();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:mtrelay.java

示例10: main

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

        Context context = ZMQ.context(1);
    
        //  Bind to inproc: endpoint, then start upstream thread
        Socket receiver = context.socket(ZMQ.PAIR);
        receiver.bind("inproc://step3");
        
        //  Step 2 relays the signal to step 3
        Thread step2 = new Step2 (context);
        step2.start();
        
        //  Wait for signal
        receiver.recv(0);
        receiver.close ();
    
        System.out.println ("Test successful!");
        context.term ();
    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:mtrelay.java

示例11: main

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

        Context context = ZMQ.context(1);

        Socket clients = context.socket(ZMQ.ROUTER);
        clients.bind ("tcp://*:5555");

        Socket workers = context.socket(ZMQ.DEALER);
        workers.bind ("inproc://workers");

        for(int thread_nbr = 0; thread_nbr < 5; thread_nbr++) {
            Thread worker = new Worker (context);
            worker.start();
        }
        //  Connect work threads to client threads via a queue
        ZMQ.proxy (clients, workers, null);

        //  We never get here but clean up anyhow
        clients.close();
        workers.close();
        context.term();
    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:23,代码来源:mtserver.java

示例12: main

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

    //  First, connect our subscriber socket
    Socket subscriber = context.socket(ZMQ.SUB);
    subscriber.connect("tcp://localhost:5561");
    subscriber.subscribe(ZMQ.SUBSCRIPTION_ALL);

    //  Second, synchronize with publisher
    Socket syncclient = context.socket(ZMQ.REQ);
    syncclient.connect("tcp://localhost:5562");

    //  - send a synchronization request
    syncclient.send(ZMQ.MESSAGE_SEPARATOR, 0);

    //  - wait for synchronization reply
    syncclient.recv(0);

    //  Third, get our updates and report how many we got
    int update_nbr = 0;
    while (true) {
        String string = subscriber.recvStr(0);
        if (string.equals("END")) {
            break;
        }
        update_nbr++;
    }
    System.out.println("Received " + update_nbr + " updates.");

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

示例13: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Send a string using ZMQ. The program has been originally used for sending control messages in Idommar.
 * @param args
 */
public static void main(String[] args) throws Exception {

	if ( args.length < 2 ) {
		System.out.println("missing parameters");
		return;
	}

	try {
		// read the command line arguments and create a ZMQ context.
		String address = args[0];
		String command = args[1];
		Context context = ZMQ.context(1);
		Socket controlSocket = context.socket(ZMQ.REQ);
		//System.out.println("ALGO: ZMQ created context");
		
		// configure the ZMQ connection
		controlSocket.setReceiveTimeOut(10000);
		controlSocket.connect(address);
		
		// send the command
		controlSocket.send(command);
		//System.out.println("ZMQ connected to socket");
		
		// close the socket and terminate the context.
		controlSocket.close();
		context.term();
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(0);
	}
}
 
开发者ID:jasjisdo,项目名称:spark-newsreel-recommender,代码行数:36,代码来源:StringSender.java

示例14: execute

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void execute(ServiceContext serviceContext) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket responder = context.socket(ZMQ.REP);
    responder.connect(zeroMqBrokerAddress);
    ZMQ.PollItem items[] = {new ZMQ.PollItem(responder, ZMQ.Poller.POLLIN)};
    while (!Thread.currentThread().isInterrupted() && !serviceContext.isCancelled()) {
        //  Wait for next request from client
        int rc = ZMQ.poll(items, 1000);
        if (rc == -1) {
            continue;
        }

        if (items[0].isReadable()) {
            String reqStr = responder.recvStr(0);
            System.out.printf("Received request: [%s]\n", reqStr);

            ValidateRequest req = objectMapper.readValue(reqStr, ValidateRequest.class);

            ValidateResponse result = validateOperation(req.getAccount(), req.getSum());
            System.out.printf("send response request: [%s]\n", result);

            responder.send(objectMapper.writeValueAsString(result));
        }
    }
    System.out.println("Stop async read!");

    //  We never get here but clean up anyhow
    responder.close();
    context.term();

}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:36,代码来源:AsyncBankServiceImpl.java

示例15: run

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

    Context context = ZMQ.context(1);
    Socket worker = context.socket(ZMQ.REQ);
    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.send ("Hi Boss");

        //  Get workload from broker, until finished
        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,代码行数:33,代码来源:rtreq.java


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