smart-socket v1.4.4 Bate release, late UDP traffic

smart-socket is a domestic open-source Java AIO framework, the pursuit of the amount of code, performance, stability, and all aspects of interface design to achieve the ultimate. If the smart-socket a hint to help, please look at our Star project and keep up to you; if you are not satisfied with smart-socket, that like him some patience, smart-socket has been trying to get better.

The beta version of the main capabilities provide UDP communications services for smart-socket, which is the function of many users care deeply about. We first pass under a simple demo on how to use smart-socket communication development of UDP.

public class UdpDemo {
    public static void main(String[] args) throws IOException, InterruptedException {

        //服务端
        final UdpBootstrap<String, String> bootstrap = new UdpBootstrap<String, String>(new StringProtocol(), new MessageProcessor<String, String>() {
            @Override
            public void process(UdpChannel<String, String> channel, SocketAddress remote, String msg) {
                InetSocketAddress remoteAddress = (InetSocketAddress) remote;
                if (remoteAddress.getPort() == 9999) {
                    System.out.println(channel + " receive response:" + msg);
                } else {
                    System.out.println("server receive request:" + msg);
                    try {
                        channel.write(msg, remote);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        bootstrap.open(9999);
        System.out.println("启动成功");

        //客户端
        int i = 10;
        final SocketAddress remote = new InetSocketAddress("localhost", 9999);
        while (i-- > 0) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        int count = 10;
                        UdpChannel<String, String> channel = bootstrap.open();
                        while (count-- > 0) {
                            channel.write("HelloWorld", remote);
                        }
                        System.out.println("发送完毕");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }
        Thread.sleep(100);
        bootstrap.shutdown();
    }
}

Udp support will continue for smart-socket's style: minimalist, easy to use, high performance, and interested friends can download the code experience experience (development branch: https://gitee.com/smartboot/smart-socket/tree /1.0.0-DEV/ ).

As for the official version of the release date to be determined, because the smart-socket interface design integration expectations TCP, UDP, try to use only develop once the user can seamlessly switch communication.

Guess you like

Origin www.oschina.net/news/109245/smart-socket-1-4-4-beta-released