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

国外的素材网站外贸网站怎么做会吸引眼球

国外的素材网站,外贸网站怎么做会吸引眼球,企业所得税优惠政策最新2023规定,怎么查看wordpress主题使用NettySpringBoot方式可以快速地开发一套基于UDP协议的服务端程序#xff0c;同样的也可以开发客户端#xff0c;一般使用UDP都是使用原生的方式#xff0c;发送消息后就不管不问#xff0c;也就是不需要确定消息是否收到#xff0c;这里使用Netty创建的客户端和服务端…使用NettySpringBoot方式可以快速地开发一套基于UDP协议的服务端程序同样的也可以开发客户端一般使用UDP都是使用原生的方式发送消息后就不管不问也就是不需要确定消息是否收到这里使用Netty创建的客户端和服务端倒是能够类似http协议那样请求数据得到返回数据实际上得到的就是服务端原路返回的数据。 1、这里也使用SpringBootNetty创建pom.xml文件导入依赖包 ​propertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version1.8/java.version/propertiesparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.1.6.RELEASE/versionrelativePath / !-- lookup parent from repository --/parentdependencies!--web模块的启动器 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- netty依赖 springboot2.x自动导入版本 --dependencygroupIdio.netty/groupIdartifactIdnetty-all/artifactId/dependency/dependencies 2、Netty客户端的类包含main方法这里就没有使用SpringBoot方式的启动 package boot.netty.udp.client;import java.net.InetSocketAddress; import boot.netty.udp.client.adapter.BootNettyUdpClientSimpleChannelInboundHandler; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.util.CharsetUtil;public class BootNettyUdpClient {public void bind(String address, int port, String data) {EventLoopGroup eventLoopGroup new NioEventLoopGroup();try {Bootstrap clientBootstrap new Bootstrap();clientBootstrap clientBootstrap.group(eventLoopGroup);clientBootstrap clientBootstrap.channel(NioDatagramChannel.class);clientBootstrap clientBootstrap.option(ChannelOption.SO_BROADCAST, true);clientBootstrap clientBootstrap.handler(new BootNettyUdpClientSimpleChannelInboundHandler());Channel channel clientBootstrap.bind(0).sync().channel();channel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(data, CharsetUtil.UTF_8),new InetSocketAddress(address,port))).sync();// 与BootNettyUdpClientSimpleChannelInboundHandler中的ctx.channel().id().toString()是一样的值System.out.println(channnel id channel.id().toString());// 方式一查询等待超时 单位s 等待服务端原路返回的消息// 在channelRead0(ChannelHandlerContext ctx, DatagramPacket msg)方法中// 收到消息后可主动关闭channel此处等待自然释放 channel.closeFuture().await(10000);// 方式二直接等待服务端原路返回后在channelRead0(ChannelHandlerContext ctx, DatagramPacket msg)方法中// 收到消息后可主动关闭channe// 若服务端没有原路返回消息或者消息未收到将会一直等待浪费资源//channel.closeFuture().sync();} catch (Exception e) {// TODO: handle exception} finally {System.out.println(netty client udp close!);eventLoopGroup.shutdownGracefully();}}public static void main(String[] args) {// 向网段内的所有机器广播UDP消息这个没试过是不是这个原理// new BootNettyUdpClient().bind(255.255.255.255,9999,I am client);// 指定某个套接字地址和发送的内容可以发送消息// 该方式也可以封装成一个udp的客户端的send类new BootNettyUdpClient().bind(127.0.0.1,9999,I am client);}} 3、服务端I/O数据读写处理类 package boot.netty.udp.client.adapter;import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.socket.DatagramPacket; import io.netty.util.CharsetUtil;public class BootNettyUdpClientSimpleChannelInboundHandler extends SimpleChannelInboundHandlerDatagramPacket {Overrideprotected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {try {String strdata msg.content().toString(CharsetUtil.UTF_8);//打印收到的消息System.out.println(msg---strdata);// 与BootNettyUdpClient中的channel.id().toString()是一样的值System.out.println(ctx.channel().id().toString());// 收到服务端原路返回的消息后不需要再次向服务端发送消息, 可以在这里暴力关闭也可以在 channelReadComplete(ChannelHandlerContext ctx)内// ctx.close();} catch (Exception e) {}}/*** 重写方法* 结构* 1.public class BootNettyUdpClientSimpleChannelInboundHandler extends SimpleChannelInboundHandlerDatagramPacket** 2.public abstract class SimpleChannelInboundHandlerI extends ChannelInboundHandlerAdapter** 3.public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelInboundHandler** ChannelInboundHandlerAdapter类有诸多方法可以重写可以根据具体需求来写**/Overridepublic void channelReadComplete(ChannelHandlerContext ctx) throws Exception {super.channelReadComplete(ctx);System.out.println(关闭channel);ctx.close();}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {cause.printStackTrace();ctx.close();}}4、我们可以启动一个服务端(SpringBoot搭建基于UDP协议的服务端)然后调用main方法可以看到服务端可以收到消息客户端也可以收到服务端原路返回的时间戳消息public static void main(String[] args) {// 向网段内的所有机器广播UDP消息这个没试过是不是这个原理// new BootNettyUdpClient().bind(255.255.255.255,9999,I am client);// 指定某个套接字地址和发送的内容可以发送消息// 该方式也可以封装成一个udp的客户端的send类new BootNettyUdpClient().bind(127.0.0.1,9999,I am client);} 4、我们可以启动一个服务端(SpringBoot搭建基于UDP协议的服务端)然后调用main方法可以看到服务端可以收到消息客户端也可以收到服务端原路返回的时间戳消息 public static void main(String[] args) {// 向网段内的所有机器广播UDP消息这个没试过是不是这个原理// new BootNettyUdpClient().bind(255.255.255.255,9999,I am client);// 指定某个套接字地址和发送的内容可以发送消息// 该方式也可以封装成一个udp的客户端的send类new BootNettyUdpClient().bind(127.0.0.1,9999,I am client);}
http://www.huolong8.cn/news/5491/

相关文章:

  • mysql 收费 网站建设网站留言板的作用
  • 月饼网站建设wordpress英文版 菜单
  • o2o的网站有哪些成都网站建设服务
  • 做粘土网站棋牌游戏在哪做网站
  • 松岗网站设计青海西宁制作网站企业
  • 公司网站制作站制作网站建设行业发展
  • 有哪些网站可以做微商二级网站建设与管理会议
  • 小网站设计二次开发源代码
  • 网网站站建建设设装修设计专业
  • 全屏网站制作短视频公司网站建设方案
  • 潍坊网站建设团队免备案网站制作
  • 网站建设系统设计报告某学校网站建设方案论文
  • 工商做年报网站做淘客网站需要什么
  • 海原县建设局网站泰安网站建设公司带
  • 网站开发难题深圳微商城网站制作
  • 邢台网站网站建设网站设计与建设的参考文献
  • 网站开发案例php网站html地图模板
  • 做网站需要服务器和什么软件wordpress 没有保存
  • 网站设计与实现环保主题静态网站
  • 都安做网站中国建设协会官网
  • 怎么使用模板建设网站iis默认网站删除
  • 青岛网络推广建站seo网站排名推广
  • 手机销售网站的设计与实现wordpress 做博客
  • 苏州网站开发公司济南兴田德润地址十堰专业网站建设公司
  • 电商网站后台建设工程做网站
  • 做mip网站需要多钱.net电子商务网站开发
  • 微信公众好第三方网站怎么做医疗器械网站建设方案
  • 建行移动门户网站wordpress是不是很慢
  • 设计接单的网站wordpress图片被拉伸
  • wordpress建站需要写代码吗如何做网络营销推广啃26金手指效果牛x