package org.sim0mq.demo; import org.djutils.serialization.SerializationException; import org.sim0mq.Sim0MQException; import org.sim0mq.message.MessageStatus; import org.sim0mq.message.SimulationMessage; import org.zeromq.ZContext; import org.zeromq.ZMQ; /** * Server example for JeroMQ / ZeroMQ. *

* (c) copyright 2015-2019 Delft University of Technology.
* BSD-style license. See DSOL License.
* @author Alexander Verbraeck * @version Oct 21, 2016 */ public final class Server { /** */ private Server() { // Utility class } /** * @param args command line arguments * @throws Sim0MQException on error * @throws SerializationException on serialization problem */ public static void main(final String[] args) throws Sim0MQException, SerializationException { ZContext context = new ZContext(1); // Socket to talk to clients ZMQ.Socket responder = context.createSocket(ZMQ.REP); responder.bind("tcp://*:5556"); while (!Thread.currentThread().isInterrupted()) { // Wait for next request from the client byte[] request = responder.recv(0); Object[] message = SimulationMessage.decode(request); System.out.println("Received " + SimulationMessage.print(message)); // send a reply Object[] reply = new Object[] { true, -28.2, 77000, "Bangladesh" }; responder.send(SimulationMessage.encodeUTF8("IDVV14.2", "MC.1", "MM1.4", "TEST.2", 1201L, MessageStatus.NEW, reply), 0); } responder.close(); context.destroy(); context.close(); } }