Netty Echo服务器/客户端-SSL不起作用

时间:2018-07-06 15:54:14

标签: ssl netty

我想在邮件中添加SSL,然后我去看there中netty的示例。

例如:Echo服务器

public final class EchoServer {

static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", "8007"));

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;}

我有一些问题。 我没有意识到System.getProperty(“ ssl”)是什么意思?我测试此代码并获取我的“ SSL”为空,为什么?我还使用wireshark获取连接,但未获得ssl连接。

3 个答案:

答案 0 :(得分:1)

使用此:

static final boolean SSL = System.getProperty("ssl") != null;   
static final String HOST = System.getProperty("host", "127.0.0.1");   
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));

答案 1 :(得分:0)

如果要在此示例中启用SSL,则应以“ -Dssl”开头,该示例将启用SSL。

Netty本身还包含一些脚本,以使您在从git签出源代码时更加轻松:

./run-example.sh -Dssl echo-server
./run-example.sh -Dssl echo-client

答案 2 :(得分:0)

您可以使用;

静态最终布尔SSL = true;

static final int PORT = Integer.parseInt(System.getProperty(“ port”,SSL?“ 8443”:“ 8080”));

资源代码:https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/helloworld

相关问题