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

建设厅试验员考试报名网站自己电脑做局域网网站服务器

建设厅试验员考试报名网站,自己电脑做局域网网站服务器,336633域名,青岛网站制作公司网络1.Netty服务端 服务端代码参考【基于Netty实现安全认证的WebSocket#xff08;wss#xff09;服务端-CSDN博客】 2.Netty客户端 客户端代码参考【基于Netty实现WebSocket客户端-CSDN博客】中两种都可以#xff1b;这里用的是第一种。 新增SslHandler的代码#xff1a; …1.Netty服务端 服务端代码参考【基于Netty实现安全认证的WebSocketwss服务端-CSDN博客】 2.Netty客户端 客户端代码参考【基于Netty实现WebSocket客户端-CSDN博客】中两种都可以这里用的是第一种。 新增SslHandler的代码 SslContext sslCtx SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); ... pipeline.addLast(sslCtx.newHandler(sc.alloc(), webSocketURL.getHost(), webSocketURL.getPort())); 服务端地址的协议头调整为wss final URI webSocketURL new URI(wss://127.0.0.1:7070/helloWs); 完整的客户端代码如下 import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory; import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.stream.ChunkedWriteHandler; import lombok.extern.slf4j.Slf4j;import java.net.URI; import java.util.concurrent.CountDownLatch;/*** https://blog.csdn.net/a1053765496/article/details/130701218* 基于Netty快速实现WebSocket客户端不手动处理握手*/ Slf4j public class SimpleWssClient {final CountDownLatch latch new CountDownLatch(1);public static void main(String[] args) throws Exception {SimpleWssClient client new SimpleWssClient();client.test();}public void test() throws Exception {Channel dest dest();latch.await();dest.writeAndFlush(new TextWebSocketFrame(CountDownLatch完成后发送的消息));}public Channel dest() throws Exception {final URI webSocketURL new URI(wss://127.0.0.1:7070/helloWs);EventLoopGroup group new NioEventLoopGroup();SslContext sslCtx SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();Bootstrap boot new Bootstrap();boot.option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.TCP_NODELAY, true).group(group).handler(new LoggingHandler(LogLevel.INFO)).channel(NioSocketChannel.class).handler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel sc) throws Exception {ChannelPipeline pipeline sc.pipeline();pipeline.addLast(sslCtx.newHandler(sc.alloc(), webSocketURL.getHost(), webSocketURL.getPort()));pipeline.addLast(new HttpClientCodec());pipeline.addLast(new ChunkedWriteHandler());pipeline.addLast(new HttpObjectAggregator(64 * 1024));pipeline.addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(webSocketURL, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));pipeline.addLast(new SimpleChannelInboundHandlerTextWebSocketFrame() {Overrideprotected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg)throws Exception {System.err.println( 客户端收到消息 msg.text());}Overridepublic void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {if (WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE.equals(evt)) {log.info(ctx.channel().id().asShortText() 握手完成);latch.countDown();send(ctx.channel());}super.userEventTriggered(ctx, evt);}});}});ChannelFuture cf boot.connect(webSocketURL.getHost(), webSocketURL.getPort()).sync();return cf.channel();}public static void send(Channel channel) {final String textMsg 握手完成后直接发送的消息;if (channel ! null channel.isActive()) {TextWebSocketFrame frame new TextWebSocketFrame(textMsg);channel.writeAndFlush(frame).addListener((ChannelFutureListener) channelFuture - {if (channelFuture.isDone() channelFuture.isSuccess()) {log.info( 发送成功.);} else {channelFuture.channel().close();log.info( 发送失败. cause channelFuture.cause());channelFuture.cause().printStackTrace();}});} else {log.error(消息发送失败 textMsg textMsg);}}} 参考利用netty开发webScoketClient支持wss协议客户端、服务端心跳实现_websocketclient-CSDN博客
http://www.pierceye.com/news/287150/

相关文章:

  • 做简历模板的网站都有哪些wordpress是啥东西
  • 网站流量渠道湖州做网站优化
  • 汽车网站哪个好预付的网站开发费用怎么入账
  • 网站代管理哪个网站有介绍拿到家做的手工活
  • 惊艳的网站网站建设实训过程报告
  • 秦皇岛做网站公司企业网站备案需要什么
  • 做网站必须开厂吗科协网站建设建议
  • 西宁 网站建设凡科做视频网站
  • wordpress中文主题 wp-cmsseo排名赚钱
  • 优质的网站制作在线查企业信息查询平台
  • 天津网站建设学习电子商务企业网站建设实训报告
  • 怎么让网站收录在google怎么免费安装wordpress主题
  • 在windows2003上做网站浙江网
  • 宣威网站wordpress把logo变大
  • 网站设计模式有哪些商城网站营销方案
  • mvc做的网站wordpress 新建php文件
  • 西安网站seo外包个人开发者
  • 注册网站需要visa怎么办济宁万达网站建设
  • niche网站建设wordpress安装文本编辑器
  • 网站建设三种方法免费的导航页
  • 微信到wordpress杭州网站怎么做seo
  • 沙田镇仿做网站网站加速器quickq
  • 武进网站建设医药公司网站建设
  • 专业做网站建设广告设计网站素材
  • 成都建设银行保安招聘网站深圳做兼职的网站设计
  • 做网站如何找广告商湖南网站建设kaodezhu
  • 宁波专业的网站搭建公司天津网站建设技术托管
  • 做水果网站特点分析报告怎样在百度上注册自己的公司
  • 800元五合一建站上海企业排行榜
  • 学校建设网站前的市场分析上海到北京火车时刻表查询