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



我想为消息添加SSL,我从那里去看netty的例子。

例如:回显服务器

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 连接。

使用这个:

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"));

如果要在本例中启用SSL,则应以"-DSSL"开头,这将为该示例启用SSL。

Netty 本身还包括一些脚本,以便在您从 git 中签出源代码时更容易:

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

您可以使用;

静态最终布尔 SSL = 真;

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

最新更新