GeezerVison is showing github.com — Fix DiscardClient hang under -Dssl by using a client SSL context (#16… · netty/netty@b55fabc
File tree
Expand file treeCollapse file tree
Open diff view settings
example/src/main/java/io/netty/example/discard
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: example/src/main/java/io/netty/example/discard/DiscardClient.java +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
23 | 23 | import io.netty.channel.nio.NioEventLoopGroup; |
24 | 24 | import io.netty.channel.socket.SocketChannel; |
25 | 25 | import io.netty.channel.socket.nio.NioSocketChannel; |
26 | | -import io.netty.example.util.ServerUtil; |
27 | 26 | import io.netty.handler.ssl.SslContext; |
| 27 | +import io.netty.handler.ssl.SslContextBuilder; |
| 28 | +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; |
28 | 29 |
|
29 | 30 | /** |
30 | 31 | * Keeps sending random data to the specified address. |
31 | 32 | */ |
32 | 33 | public final class DiscardClient { |
33 | 34 |
|
| 35 | + static final boolean SSL = System.getProperty("ssl") != null; |
34 | 36 | static final String HOST = System.getProperty("host", "127.0.0.1"); |
35 | 37 | static final int PORT = Integer.parseInt(System.getProperty("port", "8009")); |
36 | 38 | static final int SIZE = Integer.parseInt(System.getProperty("size", "256")); |
37 | 39 |
|
38 | 40 | public static void main(String[] args) throws Exception { |
39 | 41 | // Configure SSL. |
40 | | - final SslContext sslCtx = ServerUtil.buildSslContext(); |
| 42 | + final SslContext sslCtx; |
| 43 | + if (SSL) { |
| 44 | + sslCtx = SslContextBuilder.forClient() |
| 45 | + .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); |
| 46 | + } else { |
| 47 | + sslCtx = null; |
| 48 | + } |
41 | 49 |
|
42 | 50 | EventLoopGroup group = new NioEventLoopGroup(); |
43 | 51 | try { |
|