private ZMQ.Socket getNewSocket(int type, int port, String connection, ZMQ.Context context) { ZMQ.Socket socket = context.socket(type); socket.bind(connection + ":" + String.valueOf(port)); return socket; }
/** * Bind to network interface to a random port. Start listenting for new connections. * The main difference from bindToRandomPort is that it allows system to pick up the right port. * For this reason return type is a string and its responsibility of a caller to parse into * the right integer type (e.g. for vmci transport it should be long). * * @param addr the endpoint to bind to. */ public String bindToSystemRandomPort(String addr) { if (ZMQ.version_full() < ZMQ.make_version(3, 2, 0)) throw new UnsupportedOperationException(); bind(String.format("%s:*", addr)); byte[] endpoint_bytes = getBytesSockopt(LAST_ENDPOINT); // NULL-terminated String endpoint_str = new String(Arrays.copyOf(endpoint_bytes, endpoint_bytes.length - 1)); String port = endpoint_str.substring(endpoint_str.lastIndexOf(":") + 1); return port; }
/** * Bind to network interface to a random port. Start listening for new connections. * * @param addr the endpoint to bind to. * @param min_port The minimum port in the range of ports to try. * @param max_port The maximum port in the range of ports to try. * @param max_tries The number of attempt to bind. */ public int bindToRandomPort(String addr, int min_port, int max_port, int max_tries) { int port; Random rand = new Random(); for (int i = 0; i < max_tries; i++) { port = rand.nextInt(max_port - min_port + 1) + min_port; try { bind(String.format("%s:%s", addr, port)); return port; } catch (ZMQException e) { if (e.getErrorCode() != ZMQ.EADDRINUSE()) { throw e; } continue; } } throw new ZMQException("Could not bind socket to random port.", (int) ZMQ.EADDRINUSE()); }
public ZeroMQDeliveryAsync(String name){ if (name.endsWith(":")){ name = name.substring(0, name.length()-1); } this.name = name; context = Main.getZmqContext(); // Socket to talk to clients publisher = context.createSocket(ZMQ.PUB); publisher.setLinger(5000); publisher.setSndHWM(0); // no limit publisher.bind("inproc://stream/"+name); Main.getZmqProxy().connectTo(name); closed = false; }
private void bind() { if (socket != null) { // Socket is still active, ignore. This can happen if bind is called after the receiver has been rescheduled return; } manager.reserve(id); socket = manager.getContext().socket(socketType); SocketHelper.configure(socket, metadata); address.getPort().bind(Port.TYPE.TCP); socket.bind(address.toProtocolString()); controlSocket = manager.createControlSocket(); poller = manager.getContext().poller(); poller.register(controlSocket, ZMQ.Poller.POLLIN); poller.register(socket, ZMQ.Poller.POLLIN); }
public WebMQPublisher(String port, String topic, String message) throws Exception { String binding = "tcp://*:" + port; context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(1000); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); publisher.sendMore(topic); boolean isSent = publisher.send(message); publisher.close(); context.term(); } }
@Override protected void start(ZMQ.Socket socket) { String addr; if (null != zmqOpts && null != zmqOpts.listenAddresses()) { addr = zmqOpts.listenAddresses(); } else { addr = "tcp://" + getListenAddress().getHostString() + ":" + getListenAddress().getPort(); } if (log.isInfoEnabled()) { String type = findSocketTypeName(socket.getType()); log.info("BIND: starting ZeroMQ {} socket on {}", type, addr); } socket.bind(addr); notifyStart(started); }
public static void runKernelDebug(Session session) throws FileNotFoundException, InvalidKeyException, UnsupportedEncodingException, IOException { Session._DEBUG_ = true; ZContext ctx = new ZContext(); Socket channel = ctx.createSocket(ZMQ.REP); channel.bind("tcp://127.0.0.1:2222"); byte[] msg = channel.recv(); String sArgs = new String(msg, StandardCharsets.UTF_8); String[] newArgs = sArgs.split(" "); channel.send("ok"); runKernel(session, newArgs); }
public Publisher(String binding, String topicName) throws Exception { mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(100); //System.out.println("Starting Publisher.."); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); this.topicName = topicName; }
@Init public void init() { // Windows requires the ZMQ library to be loaded as the JZMQ library is linked to it and Windows is unable to resolve it relative to the JZMQ library // System.loadLibrary("zmq"); ZMQLibraryInitializer.loadLibrary(hostInfo); context = ZMQ.context(1); controlSocket = context.socket(ZMQ.PUB); controlSocket.bind("inproc://fabric3"); }
public Publisher(final String endpoint) { final ZMQ.Context context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(endpoint); }
public StatePublisher(int port) { context = ZMQ.context(1); socket = context.socket(ZMQ.PUB); socket.bind("tcp://*:" + port); this.setDaemon(true); this.start(); }
@ManagementOperation(type = OperationType.POST) public void start() { manager.reserve(id); socket = manager.getContext().socket(ZMQ.PUB); SocketHelper.configure(socket, metadata); address.getPort().bind(Port.TYPE.TCP); socket.bind(address.toProtocolString()); }
@Override public void prepare() { ZMQ.Context context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind("tcp://*:5563"); }
@ManagementOperation(type = OperationType.POST) public void start() { manager.reserve(id); socket = manager.getContext().socket(ZMQ.PUB); SocketHelper.configure(socket, metadata); address.getPort().bind(Port.TYPE.TCP); socket.bind(address.toProtocolString()); }
@Init public void init() { // Windows requires the ZMQ library to be loaded as the JZMQ library is linked to it and Windows is unable to resolve it relative to the JZMQ library // System.loadLibrary("zmq"); loadLibrary(hostInfo); context = ZMQ.context(1); controlSocket = context.socket(ZMQ.PUB); controlSocket.bind("inproc://fabric3"); }
public static Socket bind(Socket socket, String url) { socket.bind(url); return socket; }