Java Code Examples for io.vertx.core.net.NetSocket#closeHandler()
The following examples show how to use
io.vertx.core.net.NetSocket#closeHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecureScuttlebuttVertxClient.java From incubator-tuweni with Apache License 2.0 | 6 votes |
NetSocketClientHandler( NetSocket socket, Signature.PublicKey remotePublicKey, ClientHandlerFactory<T> handlerFactory, CompletableAsyncResult<T> completionHandle) { this.socket = socket; this.handshakeClient = SecureScuttlebuttHandshakeClient.create(keyPair, networkIdentifier, remotePublicKey); this.handlerFactory = handlerFactory; this.completionHandle = completionHandle; socket.closeHandler(res -> { if (handler != null) { handler.streamClosed(); } }); socket.exceptionHandler(e -> logger.error(e.getMessage(), e)); socket.handler(this::handle); socket.write(Buffer.buffer(handshakeClient.createHello().toArrayUnsafe())); }
Example 2
Source File: SecureScuttlebuttVertxClient.java From cava with Apache License 2.0 | 6 votes |
NetSocketClientHandler( Logger logger, NetSocket socket, Signature.PublicKey remotePublicKey, ClientHandlerFactory<T> handlerFactory, CompletableAsyncResult<T> completionHandle) { this.logger = logger; this.socket = socket; this.handshakeClient = SecureScuttlebuttHandshakeClient.create(keyPair, networkIdentifier, remotePublicKey); this.handlerFactory = handlerFactory; this.completionHandle = completionHandle; socket.closeHandler(res -> { if (handler != null) { handler.streamClosed(); } }); socket.exceptionHandler(e -> logger.error(e.getMessage(), e)); socket.handler(this::handle); socket.write(Buffer.buffer(handshakeClient.createHello().toArrayUnsafe())); }
Example 3
Source File: TcpServerConnection.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
public void init(NetSocket netSocket) { // currently, socket always be NetSocketImpl this.initNetSocket((NetSocketImpl) netSocket); String remoteAddress = netSocket.remoteAddress().toString(); LOGGER.info("connect from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); netSocket.exceptionHandler(e -> { LOGGER.error("disconected from {}, in thread {}, cause {}", remoteAddress, Thread.currentThread().getName(), e.getMessage()); }); netSocket.closeHandler(Void -> { LOGGER.error("disconected from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); }); netSocket.handler(splitter); }
Example 4
Source File: ProtocolGateway.java From hono with Eclipse Public License 2.0 | 6 votes |
void handleConnect(final NetSocket socket) { final Map<String, Object> dict = new HashMap<>(); final RecordParser commandParser = RecordParser.newDelimited("\n", socket); commandParser.endHandler(end -> socket.close()); commandParser.exceptionHandler(t -> { LOG.debug("error processing data from device", t); socket.close(); }); commandParser.handler(data -> handleData(socket, dict, data)); socket.closeHandler(remoteClose -> { LOG.debug("device closed connection"); Optional.ofNullable((CommandConsumer) dict.get(KEY_COMMAND_CONSUMER)) .ifPresent(c -> { c.close(res -> { LOG.debug("closed device's command consumer"); }); }); socket.close(); }); socket.write(String.format("Welcome to the Protocol Gateway for devices of tenant [%s], please enter a command\n", tenant)); LOG.debug("connection with client established"); }
Example 5
Source File: SecureScuttlebuttVertxServer.java From incubator-tuweni with Apache License 2.0 | 5 votes |
void handle(NetSocket netSocket) { this.netSocket = netSocket; netSocket.closeHandler(res -> { if (handler != null) { handler.streamClosed(); } }); netSocket.handler(this::handleMessage); }
Example 6
Source File: StratumServer.java From besu with Apache License 2.0 | 5 votes |
private void handle(final NetSocket socket) { StratumConnection conn = new StratumConnection( protocols, socket::close, bytes -> socket.write(Buffer.buffer(bytes))); socket.handler(conn::handleBuffer); socket.closeHandler(conn::close); }
Example 7
Source File: SecureScuttlebuttVertxServer.java From cava with Apache License 2.0 | 5 votes |
void handle(NetSocket netSocket) { this.netSocket = netSocket; netSocket.closeHandler(res -> { if (handler != null) { handler.streamClosed(); } }); netSocket.handler(this::handleMessage); }
Example 8
Source File: VertxEcho.java From vertx-in-action with MIT License | 5 votes |
private static void handleNewClient(NetSocket socket) { numberOfConnections++; socket.handler(buffer -> { socket.write(buffer); if (buffer.toString().endsWith("/quit\n")) { socket.close(); } }); socket.closeHandler(v -> numberOfConnections--); }
Example 9
Source File: TcpClientConnection.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void onConnectSuccess(NetSocket socket) { LOGGER.info("connected to address {} success in thread {}.", socketAddress.toString(), Thread.currentThread().getName()); // currently, socket always be NetSocketImpl this.initNetSocket((NetSocketImpl) socket); socket.handler(new TcpParser(this::onReply)); socket.exceptionHandler(this::onException); socket.closeHandler(this::onClosed); // 开始登录 tryLogin(); }
Example 10
Source File: ServerHandler.java From shadowsocks-vertx with Apache License 2.0 | 5 votes |
private void setFinishHandler(NetSocket socket) { socket.closeHandler(v -> { destory(); }); socket.endHandler(v -> { destory(); }); socket.exceptionHandler(e -> { log.error("Catch Exception." + e.toString()); destory(); }); }
Example 11
Source File: ClientHandler.java From shadowsocks-vertx with Apache License 2.0 | 5 votes |
private void setFinishHandler(NetSocket socket) { socket.closeHandler(v -> { destory(); }); socket.endHandler(v -> { destory(); }); socket.exceptionHandler(e -> { log.error("Catch Exception:" + e.toString()); destory(); }); }
Example 12
Source File: TelnetSocketHandler.java From vertx-shell with Apache License 2.0 | 5 votes |
@Override public void handle(final NetSocket socket) { TelnetHandler handler = factory.get(); final VertxTelnetConnection connection = new VertxTelnetConnection(handler, Vertx.currentContext(), socket); socket.handler(event -> connection.receive(event.getBytes())); socket.closeHandler(event -> connection.onClose()); connection.onInit(); }