package nl.tudelft.simulation.zmq.test; import org.zeromq.ZMQ; /** * Client example for JeroMQ / ZeroMQ. *
* Copyright (c) 2002-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Alexander Verbraeck */ public class Client { /** * @param args String[]; */ public static void main(String[] args) { ZMQ.Context context = ZMQ.context(1); // Socket to talk to server System.out.println("Connecting to hello world server…"); ZMQ.Socket requester = context.socket(ZMQ.REQ); requester.connect("tcp://localhost:5555"); for (int requestNbr = 0; requestNbr != 10; requestNbr++) { String request = "Hello"; System.out.println("Sending Hello " + requestNbr); requester.send(request.getBytes(), 0); byte[] reply = requester.recv(0); System.out.println("Received " + new String(reply) + " " + requestNbr); } requester.close(); context.term(); } }