Search in sources :

Example 1 with TcpServer

use of reactor.netty.tcp.TcpServer in project spring-boot by spring-projects.

the class NettyRSocketServerFactory method createTcpTransport.

private ServerTransport<CloseableChannel> createTcpTransport() {
    TcpServer tcpServer = TcpServer.create();
    if (this.resourceFactory != null) {
        tcpServer = tcpServer.runOn(this.resourceFactory.getLoopResources());
    }
    if (this.ssl != null && this.ssl.isEnabled()) {
        TcpSslServerCustomizer sslServerCustomizer = new TcpSslServerCustomizer(this.ssl, this.sslStoreProvider);
        tcpServer = sslServerCustomizer.apply(tcpServer);
    }
    return TcpServerTransport.create(tcpServer.bindAddress(this::getListenAddress));
}
Also used : TcpServer(reactor.netty.tcp.TcpServer)

Example 2 with TcpServer

use of reactor.netty.tcp.TcpServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    TcpServer tcpServer = TcpServer.create().handle((inbound, outbound) -> inbound.receive().then());
    // <1>
    tcpServer.warmup().block();
    DisposableServer server = tcpServer.bindNow();
    server.onDispose().block();
}
Also used : DisposableServer(reactor.netty.DisposableServer) TcpServer(reactor.netty.tcp.TcpServer)

Example 3 with TcpServer

use of reactor.netty.tcp.TcpServer in project reactor-netty by reactor.

the class MultiAddressApplication method main.

public static void main(String[] args) {
    TcpServer tcpServer = TcpServer.create();
    DisposableServer server1 = tcpServer.host(// <1>
    "localhost").port(// <2>
    8080).bindNow();
    DisposableServer server2 = tcpServer.host(// <3>
    "0.0.0.0").port(// <4>
    8081).bindNow();
    Mono.when(server1.onDispose(), server2.onDispose()).block();
}
Also used : DisposableServer(reactor.netty.DisposableServer) TcpServer(reactor.netty.tcp.TcpServer)

Example 4 with TcpServer

use of reactor.netty.tcp.TcpServer in project reactor-netty by reactor.

the class DefaultLoopResourcesTest method testServerTransportWarmup.

private void testServerTransportWarmup(boolean preferNative) {
    final DefaultLoopResources loop = (DefaultLoopResources) LoopResources.create("testServerTransportWarmup", 1, true);
    try {
        TcpServer tcpServer = TcpServer.create().runOn(loop, preferNative);
        Mono<Void> warmupMono = tcpServer.warmup();
        assertThat(loop.cacheNativeServerLoops.get()).isNull();
        assertThat(loop.cacheNativeSelectLoops.get()).isNull();
        assertThat(loop.serverLoops.get()).isNull();
        assertThat(loop.serverSelectLoops.get()).isNull();
        warmupMono.block(Duration.ofSeconds(5));
        if (preferNative && LoopResources.hasNativeSupport()) {
            assertThat(loop.cacheNativeServerLoops.get()).isNotNull();
            assertThat(loop.cacheNativeSelectLoops.get()).isNotNull();
            assertThat(loop.serverLoops.get()).isNull();
            assertThat(loop.serverSelectLoops.get()).isNull();
        } else {
            assertThat(loop.cacheNativeServerLoops.get()).isNull();
            assertThat(loop.cacheNativeSelectLoops.get()).isNull();
            assertThat(loop.serverLoops.get()).isNotNull();
            assertThat(loop.serverSelectLoops.get()).isNotNull();
        }
    } finally {
        loop.disposeLater().block(Duration.ofSeconds(5));
    }
}
Also used : TcpServer(reactor.netty.tcp.TcpServer)

Example 5 with TcpServer

use of reactor.netty.tcp.TcpServer in project reactor-netty by reactor.

the class DiscardServer method main.

public static void main(String[] args) throws Exception {
    TcpServer server = TcpServer.create().port(PORT).wiretap(WIRETAP).handle((in, out) -> {
        // Discards the incoming data and releases the buffers
        in.receive().subscribe();
        return out.neverComplete();
    });
    if (SECURE) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        server = server.secure(spec -> spec.sslContext(TcpSslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
    }
    server.bindNow().onDispose().block();
}
Also used : SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec) TcpServer(reactor.netty.tcp.TcpServer) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) TcpServer(reactor.netty.tcp.TcpServer)

Aggregations

TcpServer (reactor.netty.tcp.TcpServer)6 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)2 DisposableServer (reactor.netty.DisposableServer)2 TcpSslContextSpec (reactor.netty.tcp.TcpSslContextSpec)2