Search in sources :

Example 26 with NetServer

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();
}
Also used : AsyncFile(io.vertx.core.file.AsyncFile) OpenOptions(io.vertx.core.file.OpenOptions) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) NetServerOptions(io.vertx.core.net.NetServerOptions) Pipe(io.vertx.core.streams.Pipe) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) FileSystem(io.vertx.core.file.FileSystem) ReadStream(io.vertx.core.streams.ReadStream) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Pump(io.vertx.core.streams.Pump) Handler(io.vertx.core.Handler) NetSocket(io.vertx.core.net.NetSocket) NetServerOptions(io.vertx.core.net.NetServerOptions) NetServer(io.vertx.core.net.NetServer)

Example 27 with NetServer

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();
}
Also used : NetServer(io.vertx.core.net.NetServer) AsyncTestBase(io.vertx.test.core.AsyncTestBase) TestUtils(io.vertx.test.core.TestUtils) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) NetClient(io.vertx.core.net.NetClient) File(java.io.File) SocketAddress(io.vertx.core.net.SocketAddress) NetClient(io.vertx.core.net.NetClient) NetServer(io.vertx.core.net.NetServer)

Example 28 with NetServer

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();
}
Also used : NetServer(io.vertx.core.net.NetServer) AsyncTestBase(io.vertx.test.core.AsyncTestBase) TestUtils(io.vertx.test.core.TestUtils) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) NetClient(io.vertx.core.net.NetClient) File(java.io.File) SocketAddress(io.vertx.core.net.SocketAddress) NetServer(io.vertx.core.net.NetServer) File(java.io.File) Test(org.junit.Test)

Aggregations

NetServer (io.vertx.core.net.NetServer)28 NetServerOptions (io.vertx.core.net.NetServerOptions)20 Buffer (io.vertx.core.buffer.Buffer)16 Vertx (io.vertx.core.Vertx)15 Test (org.junit.Test)15 NetSocket (io.vertx.core.net.NetSocket)13 Handler (io.vertx.core.Handler)12 NetClient (io.vertx.core.net.NetClient)11 VertxOptions (io.vertx.core.VertxOptions)10 Pump (io.vertx.core.streams.Pump)10 HttpServer (io.vertx.core.http.HttpServer)9 ReadStream (io.vertx.core.streams.ReadStream)7 InetSocketAddress (java.net.InetSocketAddress)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 TimeUnit (java.util.concurrent.TimeUnit)7 TestUtils (io.vertx.test.core.TestUtils)6 File (java.io.File)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 AsyncFile (io.vertx.core.file.AsyncFile)5 FileSystem (io.vertx.core.file.FileSystem)5