您现在的位置是:首页 > 文章详情

smart-socket v1.4.4 Bate 版发布,迟到的 UDP 通信

日期:2019-08-21点击:557

smart-socket 是一款国产开源的 Java AIO 框架,追求代码量、性能、稳定性、接口设计各方面都达到极致。如果 smart-socket 对您有一丝帮助,请 Star 一下我们的项目并持续关注;如果您对 smart-socket 并不满意,那请多一些耐心,smart-socket 一直在努力变得更好。

本次 beta 版主要为 smart-socket 提供 UDP 通信服务的能力,这也是众多用户心心念念的功能。我们先通过一个简单的 demo了解下如何使用 smart-socket 进行 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 的支持会延续 smart-socket 的一贯风格:极简、易用、高性能,感兴趣的朋友可以下载代码体验体验(开发分支:https://gitee.com/smartboot/smart-socket/tree/1.0.0-DEV/)。

至于正式版的发布日期待定,因为smart-socket期望整合TCP、UDP的接口设计,尽量使用户用仅需开发一次便可实现无缝切换通信方式。

原文链接:https://www.oschina.net/news/109245/smart-socket-1-4-4-beta-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章