当前位置: 首页 > news >正文

呼市网站seo优化工资提成怎么算邙山郑州网站建设

呼市网站seo优化工资提成怎么算,邙山郑州网站建设,将wordpress转成app,wordpress中文免费模板下载小伙伴们,你们好呀,我是老寇,跟我一起学习使用Vertx实现UDP-Server 实现UDP【响应式】 Vertx-Core地址 注意 UDP是无连接的传输,这意味着您与远程客户端没有建立持续的连接。 所以,您发送和接收的数据包都要包含有…

小伙伴们,你们好呀,我是老寇,跟我一起学习使用Vertx实现UDP-Server

实现UDP【响应式】

Vertx-Core地址

注意

UDP是无连接的传输,这意味着您与远程客户端没有建立持续的连接。

所以,您发送和接收的数据包都要包含有远程的地址。

除此之外,UDP不像TCP的使用那样安全, 这也就意味着不能保证发送的数据包一定会被对应的接收端(Endpoint)接收。【传输数据时不建立连接,因此可能导致数据包丢失

UDP最适合一些允许丢弃数据包的应用(如监视应用程序,视频直播)。

实现过程

查看源码

代码比较简单,懒得讲解啦
代码比较简单,懒得讲解啦
代码比较简单,懒得讲解啦
服务端
引入依赖
<dependency><groupId>io.vertx</groupId><artifactId>vertx-core</artifactId><version>5.0.0</version>
</dependency>

UdpServerProperties

/*** @author laokou*/
@Data
@Component
@ConfigurationProperties(prefix = "spring.udp-server")
public class UdpServerProperties {private String host = "0.0.0.0";private Set<Integer> ports = new HashSet<>(0);private boolean broadcast = false;private boolean loopbackModeDisabled = true;private String multicastNetworkInterface = null;private boolean ipV6 = false;}

VertxUdpServer

/*** @author laokou*/
@Slf4j
public final class VertxUdpServer extends AbstractVerticle {private volatile Flux<DatagramSocket> datagramSocket;private final UdpServerProperties udpServerProperties;private boolean isClosed = false;VertxUdpServer(Vertx vertx, UdpServerProperties udpServerProperties) {this.udpServerProperties = udpServerProperties;this.vertx = vertx;}@Overridepublic synchronized void start() {datagramSocket = Flux.fromIterable(udpServerProperties.getPorts()).map(port -> {DatagramSocket datagramSocket = vertx.createDatagramSocket(getDatagramSocketOption()).handler(packet -> log.info("【Vertx-UDP-Server】 => 收到数据包:{}", packet.data()));datagramSocket.listen(port, udpServerProperties.getHost()).onComplete(result -> {if (isClosed) {return;}if (result.succeeded()) {log.info("【Vertx-UDP-Server】 => UDP服务启动成功,端口:{}", port);}else {Throwable ex = result.cause();log.error("【Vertx-UDP-Server】 => UDP服务启动失败,错误信息:{}", ex.getMessage(), ex);}});return datagramSocket;});datagramSocket.subscribeOn(Schedulers.boundedElastic()).subscribe();}@Overridepublic synchronized void stop() {isClosed = true;datagramSocket.doOnNext(socket -> socket.close().onComplete(result -> {if (result.succeeded()) {log.info("【Vertx-UDP-Server】 => UDP服务停止成功");}else {Throwable ex = result.cause();log.error("【Vertx-UDP-Server】 => UDP服务停止失败,错误信息:{}", ex.getMessage(), ex);}})).subscribeOn(Schedulers.boundedElastic()).subscribe();}public void deploy() {// 部署服务vertx.deployVerticle(this);// 停止服务Runtime.getRuntime().addShutdownHook(new Thread(this::stop));}private DatagramSocketOptions getDatagramSocketOption() {DatagramSocketOptions datagramSocketOptions = new DatagramSocketOptions();datagramSocketOptions.setBroadcast(udpServerProperties.isBroadcast());datagramSocketOptions.setLoopbackModeDisabled(udpServerProperties.isLoopbackModeDisabled());datagramSocketOptions.setMulticastNetworkInterface(udpServerProperties.getMulticastNetworkInterface());datagramSocketOptions.setIpV6(udpServerProperties.isIpV6());return datagramSocketOptions;}}

VertxUdpServerManager

/*** @author laokou*/
public final class VertxUdpServerManager {private VertxUdpServerManager() {}public static void deploy(final Vertx vertx, final UdpServerProperties properties) {new VertxUdpServer(vertx, properties).deploy();}}
客户端【测试】
/*** @author laokou*/
@Slf4j
@SpringBootTest
@RequiredArgsConstructor
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
class UdpTest {private final Vertx vertx;@Testvoid test() throws InterruptedException {for (int i = 4880; i < 5000; i++) {DatagramSocket datagramSocket = vertx.createDatagramSocket();int finalI = i;datagramSocket.send("Hello Vertx", i, "127.0.0.1").onComplete(result -> {if (result.succeeded()) {log.info("【Vertx-UDP-Client】 => 发送成功,端口:{}", finalI);}else {Throwable ex = result.cause();log.error("【Vertx-UDP-Client】 => 发送失败,端口:{},错误信息:{}", finalI, ex.getMessage(), ex);}});Thread.sleep(2000);Assertions.assertDoesNotThrow(datagramSocket::close);}}}

这可以满足基本的协议开发,自行修改即可!!!

我是老寇,我们下次再见啦!

http://www.dtcms.com/a/529790.html

相关文章:

  • 【C++】开发环境配置
  • 百度下载软件太慢了怎么办
  • 【Windows】关于搜狗浏览器安装11、12版本-区别
  • 深圳响应式设计企业网站网站建设 部署与发布视频教程
  • pyttsx3使用Windows 10的Kangkang语音
  • 3.权限(一)
  • Gurobi vs CPLEX:大规模优化求解器的选择逻辑与国产替代新选项
  • 优秀的手机网站案例走着瞧网站 设计
  • 济南网站建设外包公司福田欧曼行星
  • 建设网站的基础知识企业宣传片制作软件app
  • 【07】C语言中的浮点类型详解
  • 营销型网站代理网站上面的水印怎么做
  • 西安网站建设推荐q479185700上墙wordpress 已登录用户登录
  • 创新的南昌网站设计yandx引擎入口
  • 大兴安岭网站制作wordpress备份方法
  • 哪个网站做任务钱给得多小米的网站是哪个公司做的
  • 湖南省网站设计公司义乌网站备案
  • 网站建设人员招聘要求发布项目信息的平台
  • 输出时序分析之约束(十二)
  • 网站建设拾金手指下拉二十哪个兄弟来个直接看的网站
  • 详解C++中的文件系统
  • 《3D端游开放世界载具物理交互优化实践日志》
  • 网站空间与服务器北京做网站设计招聘
  • 如何做网站数据库房地产大数据获客软件
  • 同ip网站有什么影响莆田网站关键词优化
  • 网站logo做黑页google chrome谷歌浏览器
  • 做网站意义和目的羊毛网站建设视频
  • 网站用图怎么做文件小质量高品牌网站建设 磐石网络官方网站
  • 广州教育学会网站建设网站建设培训心得体会
  • 网站数据分析平台做外贸 网站邮箱申请