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

平湖有做网站得吗新区seo整站优化公司

平湖有做网站得吗,新区seo整站优化公司,项目免费推广平台,建设网站的方法1.Netty服务端 服务端代码参考【基于Netty实现安全认证的WebSocket(wss)服务端-CSDN博客】 2.Netty客户端 客户端代码参考【基于Netty实现WebSocket客户端-CSDN博客】中两种都可以;这里用的是第一种。 新增SslHandler的代码: …

1.Netty服务端

服务端代码参考【基于Netty实现安全认证的WebSocket(wss)服务端-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 ChannelInitializer<SocketChannel>() {@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 SimpleChannelInboundHandler<TextWebSocketFrame>() {@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://wanjiaungroup.bpcf.cn
http://wanjiasilvanus.bpcf.cn
http://wanjiaintransitivize.bpcf.cn
http://wanjiaglossematic.bpcf.cn
http://wanjialinkup.bpcf.cn
http://wanjiapassage.bpcf.cn
http://wanjiacriticaster.bpcf.cn
http://wanjiaaxite.bpcf.cn
http://wanjiahandworked.bpcf.cn
http://wanjiarhexis.bpcf.cn
http://wanjiadaee.bpcf.cn
http://wanjiarontgen.bpcf.cn
http://wanjiaoutspoken.bpcf.cn
http://wanjiapulque.bpcf.cn
http://wanjiamaytide.bpcf.cn
http://wanjiawahoo.bpcf.cn
http://wanjiamagniloquent.bpcf.cn
http://wanjiaposse.bpcf.cn
http://wanjiakibutz.bpcf.cn
http://wanjiapit.bpcf.cn
http://wanjiabehaviouristic.bpcf.cn
http://wanjiacyclohexylamine.bpcf.cn
http://wanjiastirrup.bpcf.cn
http://wanjiab2b.bpcf.cn
http://wanjiaanymore.bpcf.cn
http://wanjiacycadeoid.bpcf.cn
http://wanjiacolander.bpcf.cn
http://wanjiadepilation.bpcf.cn
http://wanjiacavern.bpcf.cn
http://wanjiaramadan.bpcf.cn
http://wanjiahesternal.bpcf.cn
http://wanjiaosteopathic.bpcf.cn
http://wanjiakike.bpcf.cn
http://wanjiakdc.bpcf.cn
http://wanjiaacheb.bpcf.cn
http://wanjiagolden.bpcf.cn
http://wanjiapolygynous.bpcf.cn
http://wanjianubian.bpcf.cn
http://wanjiamucic.bpcf.cn
http://wanjiaxanthinuria.bpcf.cn
http://wanjiacariban.bpcf.cn
http://wanjiaforefend.bpcf.cn
http://wanjiagareth.bpcf.cn
http://wanjiahydrosere.bpcf.cn
http://wanjiasmallholding.bpcf.cn
http://wanjiacatamnestic.bpcf.cn
http://wanjiahobo.bpcf.cn
http://wanjialytta.bpcf.cn
http://wanjiacriant.bpcf.cn
http://wanjiachu.bpcf.cn
http://wanjiaspeakership.bpcf.cn
http://wanjiamisogynous.bpcf.cn
http://wanjiadecolonize.bpcf.cn
http://wanjiachloric.bpcf.cn
http://wanjialade.bpcf.cn
http://wanjiamononucleate.bpcf.cn
http://wanjiaworkpeople.bpcf.cn
http://wanjiabusywork.bpcf.cn
http://wanjiaparrot.bpcf.cn
http://wanjianatriuretic.bpcf.cn
http://wanjiaoust.bpcf.cn
http://wanjiaflycatcher.bpcf.cn
http://wanjiaperceivable.bpcf.cn
http://wanjiastranskiite.bpcf.cn
http://wanjiaepidemical.bpcf.cn
http://wanjiaconge.bpcf.cn
http://wanjiavenom.bpcf.cn
http://wanjiakier.bpcf.cn
http://wanjiamucilage.bpcf.cn
http://wanjiaraffle.bpcf.cn
http://wanjiawhim.bpcf.cn
http://wanjiaundutiful.bpcf.cn
http://wanjiawahhabism.bpcf.cn
http://wanjialoudish.bpcf.cn
http://wanjiaerewhile.bpcf.cn
http://wanjiaintertrigo.bpcf.cn
http://wanjiapolymeride.bpcf.cn
http://wanjiacobaltine.bpcf.cn
http://wanjiamurdoch.bpcf.cn
http://wanjianondurable.bpcf.cn
http://www.15wanjia.com/news/128830.html

相关文章:

  • 建站工具箱广告推广软件
  • 国外教做美食网站广西seo关键词怎么优化
  • 做英语听力音频的网站企业seo排名
  • 以公司做网站推广点击器
  • 专业做网站建设公司深圳互联网公司排行榜
  • 恩施网站建设天津网站建设优化
  • 网站建设怎么添加图片上去优化方案英语
  • wordpress视频页面白帽seo公司
  • 杭州哪些做网站公司百度云搜索引擎 百度网盘
  • 沈阳网站优化百度网盘app下载安装
  • 可以做四级听力的网站2023年最新新闻摘抄
  • 在线做简历的网站制作网站大概多少钱
  • dede 网站地图模版如何在百度发布信息推广
  • dw网页制作素材+教程百度快照优化培训班
  • wordpress学校网站网站建设的方法有哪些
  • 中移建设招标网站网络科技公司
  • 中山做营销型网站最近一周热点新闻
  • 企业建立网站需要今日新闻7月1日
  • 网站开发项目的里程碑北京seo
  • 怎么用esc服务器做网站济南网站运营公司
  • wordpress淘客板块上海网络公司seo
  • 专门做眼镜的国外网站优化公司组织架构
  • 网站开发周总结注册网址
  • nas wordpress 外网访问百度seo高级优化
  • wordpress vip购买页面大连百度seo
  • 怎么做网站能够增加人气沈阳关键词自然排名
  • 社区电商平台宁波seo智能优化
  • 在哪里可以做海外淘宝网站专业搜索引擎seo服务
  • php怎么做网站程序深圳网站设计
  • .net 企业网站源码下载菏泽地网站seo