17 Haziran 2021 Perşembe

Reactor Netty TcpServer Sınıfı

bindNow metodu
Örnek
Şöyle yaparız
import reactor.netty.DisposableServer;
import reactor.netty.tcp.TcpServer;

public class Application {

  public static void main(String[] args) {
    DisposableServer server =
      TcpServer.create()
        .host("localhost")
        .port(8080)       
        .bindNow();

    server.onDispose()
      .block();     
    }
}
handle metodu
Örnek
Şöylee yaparız
import io.netty.handler.ssl.util.SelfSignedCertificate;
import reactor.netty.tcp.TcpServer;
import reactor.netty.tcp.TcpSslContextSpec;

/**
 * A TCP server that sends back the received content.
 *
 * @author Violeta Georgieva
 */
public final class EchoServer {

  static final boolean SECURE = System.getProperty("secure") != null;
  static final int PORT = Integer.parseInt(System.getProperty("port",
SECURE ? "8443" : "8080")); static final boolean WIRETAP = System.getProperty("wiretap") != null; public static void main(String[] args) throws Exception { TcpServer server = TcpServer.create() .port(PORT) .wiretap(WIRETAP) .handle((in, out) -> out.send(in.receive().retain())); if (SECURE) { SelfSignedCertificate ssc = new SelfSignedCertificate(); server = server.secure( spec -> spec.sslContext(TcpSslContextSpec.forServer(ssc.certificate(),
ssc.privateKey()))); } server.bindNow() .onDispose() .block(); } }


Hiç yorum yok:

Yorum Gönder