内容简介:smart-socket 是一款国产开源的 Java AIO 框架,追求代码量、性能、稳定性、接口设计各方面都达到极致。如果 smart-socket 对您有一丝帮助,请 Star 一下我们的项目并持续关注;如果您对 smart-socket 并不满意,...
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的接口设计,尽量使用户用仅需开发一次便可实现无缝切换通信方式。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- HBase原理-迟到的‘数据读取流程’
- HBase原理-迟到的‘数据读取流程’部分细节
- 最终一致性,一致只会迟到,但绝不会缺席
- javascript – React JS:setState在最后一次输入时迟到了
- 原生安卓的“Face ID”迟到两年 刘海都要被剪没了
- 程序员:迟到1分钟罚300,加班却视而不见,月底工资让人寒心
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
你也能看得懂的Python算法书
王硕,董文馨,张舒行,张洁 著 / 电子工业出版社 / 2018-11-1 / 59.00
编程的核心是算法,学习算法不仅能教会你解决问题的方法,而且还能为你今后的发展提供一种可能。 《你也能看得懂的Python算法书》面向算法初学者,首先介绍当下流程的编程语言Python,详细讲解Python语言中的变量和循序、分支、循环三大结构,以及列表和函数的使用,为之后学习算法打好基础。然后以通俗易懂的语言讲解双指针、哈希、深度优先、广度优先、回溯、贪心、动态规划和至短路径等经典算法。 ......一起来看看 《你也能看得懂的Python算法书》 这本书的介绍吧!