@@ -0,0 +1,2780 @@
+package com.firefly.example.tcp;%0A%0Aimport com.firefly.$;%0Aimport com.firefly.net.tcp.SimpleTcpClient;%0Aimport com.firefly.net.tcp.SimpleTcpServer;%0Aimport com.firefly.net.tcp.TcpConfiguration;%0Aimport com.firefly.net.tcp.TcpServerConfiguration;%0Aimport com.firefly.net.tcp.codec.StringParser;%0Aimport com.firefly.net.tcp.secure.openssl.DefaultOpenSSLSecureSessionFactory;%0Aimport com.firefly.utils.RandomUtils;%0Aimport com.firefly.utils.io.IO;%0A%0Aimport java.util.concurrent.Phaser;%0A%0A/**%0A * @author Pengtao Qiu%0A */%0Apublic class HelloTcpServerAndClientWithOpenssl %7B%0A    public static void main(String%5B%5D args) %7B%0A        String host = %22localhost%22;%0A        int port = (int) RandomUtils.random(1000, 65534);%0A        Phaser phaser = new Phaser(2);%0A%0A        SimpleTcpServer server = createTcpServer(host, port);%0A        SimpleTcpClient client = createTcpClient();%0A%0A        server.accept(connection -%3E %7B%0A            StringParser parser = new StringParser();%0A            parser.complete(msg -%3E %7B%0A                String str = msg.trim();%0A                switch (str) %7B%0A                    case %22quit%22: %7B%0A                        connection.write(%22bye!%5Cr%5Cn%22);%0A                        IO.close(connection);%0A                    %7D%0A                    break;%0A                    default: %7B%0A                        connection.write(%22The server received %22 + str + %22%5Cr%5Cn%22);%0A                    %7D%0A                %7D%0A            %7D);%0A            connection.receive(parser::receive);%0A        %7D).start();%0A%0A        client.connect(host, port).thenAccept(connection -%3E %7B%0A            StringParser parser = new StringParser();%0A            parser.complete(msg -%3E %7B%0A                String str = msg.trim();%0A                System.out.println(str);%0A                if (str.equals(%22bye!%22)) %7B%0A                    phaser.arrive();%0A                %7D%0A            %7D);%0A            connection.receive(parser::receive);%0A            connection.write(%22hello world%5Cr%5Cn%22).write(%22quit%5Cr%5Cn%22);%0A        %7D);%0A%0A        phaser.arriveAndAwaitAdvance();%0A        client.stop();%0A        server.stop();%0A    %7D%0A%0A    private static SimpleTcpServer createTcpServer(String host, int port) %7B%0A        TcpServerConfiguration serverConfig = new TcpServerConfiguration();%0A        serverConfig.setSecureConnectionEnabled(true);%0A        serverConfig.setSecureSessionFactory(new DefaultOpenSSLSecureSessionFactory());%0A        serverConfig.setHost(host);%0A        serverConfig.setPort(port);%0A        return $.createTCPServer(serverConfig);%0A    %7D%0A%0A    private static SimpleTcpClient createTcpClient() %7B%0A        TcpConfiguration clientConfig = new TcpConfiguration();%0A        clientConfig.setSecureConnectionEnabled(true);%0A        clientConfig.setSecureSessionFactory(new DefaultOpenSSLSecureSessionFactory());%0A        return $.createTCPClient(clientConfig);%0A    %7D%0A%7D%0A

add tcp ssl example