use of io.vertx.core.net.NetServer in project vert.x by eclipse.
the class StreamsExamples method pipe4.
public void pipe4(Vertx vertx) {
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
server.connectHandler(sock -> {
sock.handler(buffer -> {
sock.write(buffer);
if (sock.writeQueueFull()) {
sock.pause();
sock.drainHandler(done -> {
sock.resume();
});
}
});
}).listen();
}
use of io.vertx.core.net.NetServer in project vert.x by eclipse.
the class TransportTest method testNetServer.
private void testNetServer(VertxOptions options) {
vertx = Vertx.vertx(options);
NetServer server = vertx.createNetServer();
server.connectHandler(so -> {
so.handler(buff -> {
assertEquals("ping", buff.toString());
so.write("pong");
});
so.closeHandler(v -> {
testComplete();
});
});
server.listen(1234, onSuccess(v -> {
NetClient client = vertx.createNetClient();
client.connect(1234, "localhost", onSuccess(so -> {
so.write("ping");
so.handler(buff -> {
assertEquals("pong", buff.toString());
so.close();
});
}));
}));
await();
}
use of io.vertx.core.net.NetServer in project vert.x by eclipse.
the class TransportTest method testDomainSocketServer.
@Test
public void testDomainSocketServer() throws Exception {
File sock = TestUtils.tmpFile(".sock");
vertx = Vertx.vertx();
NetServer server = vertx.createNetServer();
server.connectHandler(so -> {
});
server.listen(SocketAddress.domainSocketAddress(sock.getAbsolutePath()), onFailure(err -> {
assertEquals(err.getClass(), IllegalArgumentException.class);
testComplete();
}));
await();
}
Aggregations