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

手机怎么做动漫微电影网站自己的域名可以转给做网站的账号吗

手机怎么做动漫微电影网站,自己的域名可以转给做网站的账号吗,网站建设服务标准,wordpress破解版目录 说明需求ClientServer写法总结 实现运行 说明 Netty 的一个练习#xff0c;使用 Netty 连通 服务端 和 客户端#xff0c;进行基本的通信。 需求 Client 连接服务端成功后#xff0c;打印连接成功给服务端发送消息HelloServer Server 客户端连接成功后#xff0… 目录 说明需求ClientServer写法总结 实现运行 说明 Netty 的一个练习使用 Netty 连通 服务端 和 客户端进行基本的通信。 需求 Client 连接服务端成功后打印连接成功给服务端发送消息HelloServer Server 客户端连接成功后打印连接成功读取到客户端的消息后打印到控制台并回复消息HelloClient客户端断开后打印 客户端断开连接 写法总结 对于 服务端和客户端的启动 代码基本不变可能会根据需要修改一些配置参数业务逻辑都写在各种 Handler 里根据规范需要继承Netty已有的 XxxHandler所有的 Handler 都需要在 socketChannel.pipeline() 中以链表的形式逐个执行细节放到原理分析ChannelInboundHandlerAdapter 中用到的方法 实现 导包 dependencygroupIdio.netty/groupIdartifactIdnetty-all/artifactIdversion4.1.35.Final/version/dependency创建NettyServer用于启动服务端 import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;public class NettyServer {public static void main(String[] args) throws Exception {// 创建 boss 线程组处理 连接请求个数代表有 几主每个 主 都需要配置一个单独的监听端口NioEventLoopGroup bossGroup new NioEventLoopGroup(1);// 创建 worker 线程组处理 具体业务个数代表有NioEventLoopGroup workerGroup new NioEventLoopGroup();try {ServerBootstrap serverBootstrap new ServerBootstrap();// 创建 Server 启动器配置必要参数bossGroup, workerGroup, channel, handlerserverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel socketChannel) throws Exception {// 对workerGroup的SocketChannel设置 个性化业务HandlersocketChannel.pipeline().addLast(new NettyServerHandler());}});System.out.println(Netty Server start ...);ChannelFuture channelFuture serverBootstrap.bind(9000).sync();// 给 channelFuture 添加监听器监听是否启动成功/*channelFuture.addListener(new ChannelFutureListener() {Overridepublic void operationComplete(ChannelFuture channelFuture) throws Exception {if (channelFuture.isSuccess()) {System.out.println(启动成功);} else {System.out.println(启动失败);}}});*/channelFuture.channel().closeFuture().sync();} finally {bossGroup.shutdownGracefully();workerGroup.shutdownGracefully();}} }创建NettyServerHandler实现具体业务 import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.CharsetUtil;/*** 自定义Handler需要继承netty规定好的某个HandlerAdapter (规范)* 业务逻辑* 连接成功后打印 连接成功* 收到客户端的消息时打印并回复消息** author liuhuan*/ public class NettyServerHandler extends ChannelInboundHandlerAdapter {// 当客户端连接服务器完成就会触发该方法Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {System.out.println(客户端建立连接成功);}Overridepublic void channelInactive(ChannelHandlerContext ctx) throws Exception {System.out.println(客户端断开连接);}// 读取客户端发送的数据Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {ByteBuf byteBuf (ByteBuf) msg;System.out.println(收到客户端的消息是 byteBuf.toString(CharsetUtil.UTF_8));}// 数据读取完毕时触发该方法Overridepublic void channelReadComplete(ChannelHandlerContext ctx) throws Exception {ByteBuf buf Unpooled.copiedBuffer(HelloClient.getBytes(CharsetUtil.UTF_8));ctx.writeAndFlush(buf);}// 处理异常, 一般是需要关闭通道Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {cause.printStackTrace();ctx.close();} }创建NettyClient启动客户端 import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;public class NettyClient {public static void main(String[] args) throws InterruptedException {NioEventLoopGroup group new NioEventLoopGroup();try {Bootstrap bootstrap new Bootstrap();// 创建 客户端启动器配置必要参数bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ch.pipeline().addLast(new NettyClientHandler());}});System.out.println(Netty Client start ...);ChannelFuture channelFuture bootstrap.connect(127.0.0.1, 9000).sync();channelFuture.channel().closeFuture().sync();} finally {group.shutdownGracefully();}} }创建 NettyClientHandler实现客户端业务逻辑 import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.CharsetUtil;/*** 自定义Handler需要继承netty规定好的某个HandlerAdapter (规范)* 业务逻辑连接成功后给服务端发送一条消息** author liuhuan*/ public class NettyClientHandler extends ChannelInboundHandlerAdapter {// 当客户端连接服务器完成就会触发该方法Overridepublic void channelActive(ChannelHandlerContext ctx) {System.out.println(连接建立成功);ByteBuf buf Unpooled.copiedBuffer(HelloServer.getBytes(CharsetUtil.UTF_8));ctx.writeAndFlush(buf);}//当通道有读取事件时会触发即服务端发送数据给客户端Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) {ByteBuf buf (ByteBuf) msg;System.out.println(收到服务端的消息: buf.toString(CharsetUtil.UTF_8));}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {cause.printStackTrace();ctx.close();} }运行 先执行 NettyServer 的 main 方法启动服务端查看日志执行 NettyClient 的 main 方法启动客户端查看日志关闭 NettyClient 服务查看日志重新执行 NettyClient 的 main 方法启动客户端查看日志
http://www.hkea.cn/news/14295957/

相关文章:

  • 用mui做的网站网站建设服务内容
  • 上海网站开发一对一培训网站主机的选择与优化
  • 网站开发和设计区别重庆网站建设重庆网站设计
  • 学校建网站win7+网站建设
  • 润滑油手机网站模板品牌设计和vi设计有什么区别
  • 汕头百度网站排名wordpress表单模板
  • 网站调优技能电子商务平台的特点
  • 常见网站建设工具有哪些磁力王
  • dede手机网站模板修改域名备案网站要不要关
  • 安徽太基建设官方网站品牌建设
  • 有哪些网站的搜索引擎wordpress videopro汉化
  • 电子商务网站开发的题怎么帮网站做支付接口
  • 零食网站建设的策划书网站建设能给客户带来什么
  • 鄂州网站推广优化技巧网络营销意思
  • 连锁酒店网站方案fastcomet wordpress
  • 网站建设与管理专业好不好就业做谷歌推广比较好的公司
  • 产品外观设计网站大连招聘网最新招聘
  • 怎么建设网站卖东西设计素材网站收益
  • 永州商城网站建设网页设计高端
  • 建筑公司网站管理员开发软件外包
  • 用ps怎么做学校网站页面六安本地网站
  • 凡科网上传网站低代码小程序开发平台
  • 好听好记的网站域名什么网站可以免费做视频的软件
  • 营销型网站开发流程网上动漫设计
  • 所有复刻手表网站专业做包装的电商网站
  • 江阴网站开发电商网站设计与制作论文
  • 浙江大学教室办事大厅网站建设企业网站推广论述
  • 如何招聘软件网站开发人员贵阳网站优化排名
  • 天津企业网站排名优化wordpress设置权限777
  • 邯郸网站设计公司排名怎样做音视频宣传网站