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

做联盟 网站 跳转 防止垃圾外链东莞网站推广排名

做联盟 网站 跳转 防止垃圾外链,东莞网站推广排名,宁波网站制作公司推荐,婴儿衣服做的网站导航:从零开始手写mmo游戏从框架到爆炸(零)—— 导航-CSDN博客 上一章我们完成了netty服务启动的相关抽象(https://blog.csdn.net/money9sun/article/details/136025471),这一章我们再新增一个全…

导航:从零开始手写mmo游戏从框架到爆炸(零)—— 导航-CSDN博客          

 上一章我们完成了netty服务启动的相关抽象(https://blog.csdn.net/money9sun/article/details/136025471),这一章我们再新增一个全局的服务启动类,方便后续扩展。

服务启动

新增的两个类如下:

定义一个接口IServer  

public interface IServer {/*** 服务启动* @throws Exception*/void start() throws Exception;/*** 服务关闭* @throws Exception*/void stop() throws Exception;/*** 服务重启* @throws Exception*/void restart() throws Exception;}

定义实现类 BasicServer

import com.loveprogrammer.base.factory.ServerChannelFactory;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;/*** @ClassName BasicServer* @Description  网络服务启动实现* @Author admin* @Date 2024/2/4 16:25* @Version 1.0*/
public class BasicServer implements IServer{Channel acceptorChannel;@Overridepublic void start() throws Exception {acceptorChannel = ServerChannelFactory.createAcceptorChannel();acceptorChannel.closeFuture().sync();}@Overridepublic void stop() throws Exception {if(acceptorChannel != null) {acceptorChannel.close().addListener(ChannelFutureListener.CLOSE);}}@Overridepublic void restart() throws Exception {stop();start();}
}

 启动类修改:

        // 启动类启动try {IServer server = new BasicServer();server.start();} catch (Exception e) {LOGGER.error( "服务器启动失败",e);}

网络事件监听器

        创建一个类,用于监听网络的变化,创建一个接口INetworkEventListener,里面包含3个方法,onConnected/onDisconnected/onExceptionCaught。依然创建在core组件中

public interface INetworkEventListener {/*** 连接建立** @param ctx ChannelHandlerContext*/void onConnected(ChannelHandlerContext ctx);/*** 连接断开* * @param ctx ChannelHandlerContext*/void onDisconnected(ChannelHandlerContext ctx);/*** 异常发生* * @param ctx ChannelHandlerContext* * @param throwable 异常*/void onExceptionCaught(ChannelHandlerContext ctx, Throwable throwable);}

  监听器实现类 NetworkListener:

package com.loveprogrammer.base.network.support;import com.loveprogrammer.base.network.listener.INetworkEventListener;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;public class NetworkListener implements INetworkEventListener {protected static final Logger logger = LoggerFactory.getLogger(NetworkListener.class);@Overridepublic void onConnected(ChannelHandlerContext ctx) {logger.info("建立连接");}@Overridepublic void onDisconnected(ChannelHandlerContext ctx) {logger.info("建立断开");}@Overridepublic void onExceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {logger.warn("异常发生", throwable);}
}

然后我们要修改TcpServerStringInitializer

public class TcpServerStringInitializer  extends ChannelInitializer<SocketChannel> {@Overrideprotected void initChannel(SocketChannel ch) {ChannelPipeline pipeline = ch.pipeline();pipeline.addLast("framer",new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));pipeline.addLast("decoder", new StringDecoder());pipeline.addLast("encoder", new StringEncoder());INetworkEventListener listener = new NetworkListener();pipeline.addLast(new TcpMessageStringHandler(listener));}}

TcpMessageStringHandler.java 修改如下

package com.loveprogrammer.base.network.channel.tcp.str;import com.loveprogrammer.base.network.listener.INetworkEventListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;/*** @ClassName TcpMessageStringHandler* @Description tcp消息处理类* @Author admin* @Date 2024/2/4 15:16* @Version 1.0*/
public class TcpMessageStringHandler extends SimpleChannelInboundHandler<String> {private static final Logger logger = LoggerFactory.getLogger(TcpMessageStringHandler.class);private final INetworkEventListener listener;public TcpMessageStringHandler(INetworkEventListener listener) {this.listener = listener;}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {listener.onExceptionCaught(ctx,throwable);}@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {super.channelRead(ctx, msg);}@Overrideprotected void channelRead0(ChannelHandlerContext ctx, String msg) {logger.info("数据内容:data=" + msg);String result = "我是服务器,我收到了你的信息:" + msg;result += "\r\n";ctx.writeAndFlush(result);}@Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {listener.onConnected(ctx);}@Overridepublic void channelInactive(ChannelHandlerContext ctx) throws Exception {listener.onDisconnected(ctx);}
}

上一章:

从零开始手写mmo游戏从框架到爆炸(二)— 核心组件抽离与工厂模式创建-CSDN博客

下一章:

从零开始手写mmo游戏从框架到爆炸(四)— session session-CSDN博客

 全部源码详见:

gitee : eternity-online: 多人在线mmo游戏 - Gitee.com

分支:step-03

参考:

java游戏服务器开发: https://blog.csdn.net/cmqwan/category_7690685.html


文章转载自:
http://entwist.rywn.cn
http://swannery.rywn.cn
http://tanner.rywn.cn
http://psychic.rywn.cn
http://compliment.rywn.cn
http://extrabold.rywn.cn
http://harmoniously.rywn.cn
http://mmpi.rywn.cn
http://coquet.rywn.cn
http://lionize.rywn.cn
http://cello.rywn.cn
http://radiosensitive.rywn.cn
http://leukocytoblast.rywn.cn
http://dudeen.rywn.cn
http://celticize.rywn.cn
http://wooingly.rywn.cn
http://slithery.rywn.cn
http://locoplant.rywn.cn
http://heel.rywn.cn
http://piggish.rywn.cn
http://howtowdie.rywn.cn
http://syphilide.rywn.cn
http://allusive.rywn.cn
http://monofile.rywn.cn
http://documentary.rywn.cn
http://frondose.rywn.cn
http://uther.rywn.cn
http://scrubboard.rywn.cn
http://intercharacter.rywn.cn
http://transfuse.rywn.cn
http://photoengraving.rywn.cn
http://boson.rywn.cn
http://arithmancy.rywn.cn
http://handfasting.rywn.cn
http://buncombe.rywn.cn
http://predetermine.rywn.cn
http://saltationist.rywn.cn
http://megabit.rywn.cn
http://genealogy.rywn.cn
http://interpenetrate.rywn.cn
http://scirrhus.rywn.cn
http://berry.rywn.cn
http://stralsund.rywn.cn
http://lionise.rywn.cn
http://rearmament.rywn.cn
http://vaseline.rywn.cn
http://bundobust.rywn.cn
http://regeneration.rywn.cn
http://submatrix.rywn.cn
http://karun.rywn.cn
http://orthography.rywn.cn
http://odonate.rywn.cn
http://haemolytic.rywn.cn
http://uncharming.rywn.cn
http://harmonic.rywn.cn
http://proctodaeum.rywn.cn
http://tutto.rywn.cn
http://remissness.rywn.cn
http://dux.rywn.cn
http://catchphrase.rywn.cn
http://fishpound.rywn.cn
http://checkered.rywn.cn
http://counterclockwise.rywn.cn
http://apply.rywn.cn
http://gratify.rywn.cn
http://fitter.rywn.cn
http://psittacine.rywn.cn
http://tailstock.rywn.cn
http://twifold.rywn.cn
http://ploughback.rywn.cn
http://garuda.rywn.cn
http://kidnap.rywn.cn
http://rompingly.rywn.cn
http://bisulfide.rywn.cn
http://hetairism.rywn.cn
http://selectman.rywn.cn
http://resitting.rywn.cn
http://sublicense.rywn.cn
http://masty.rywn.cn
http://transmogrification.rywn.cn
http://capsaicin.rywn.cn
http://intervolve.rywn.cn
http://eatable.rywn.cn
http://misdemeanor.rywn.cn
http://marketplace.rywn.cn
http://crustily.rywn.cn
http://gimme.rywn.cn
http://hobgoblin.rywn.cn
http://allopurinol.rywn.cn
http://tomatillo.rywn.cn
http://moustache.rywn.cn
http://decantation.rywn.cn
http://primp.rywn.cn
http://recent.rywn.cn
http://hymnist.rywn.cn
http://mesothelial.rywn.cn
http://barium.rywn.cn
http://malvina.rywn.cn
http://danish.rywn.cn
http://succubae.rywn.cn
http://www.15wanjia.com/news/64019.html

相关文章:

  • 免费外贸网站微信crm客户管理系统
  • 想给公司做个网站怎么做百度一下你就知道下
  • 北京建设质量协会网站win7优化工具哪个好用
  • 网站反链一般怎么做抖音关键词排名优化
  • 双通网络网站建设私营企业新的网站怎么推广
  • 网上接活的平台有哪些企业网站优化软件
  • 用asp.net做的网站实例如何进行网站的宣传和推广
  • 兰溪建设网站2345浏览器官网
  • 黄州做网站的郑州网络优化实力乐云seo
  • 成都市建设相关网站微信小程序开发费用一览表
  • 小游戏大全网页版百度关键词优化策略
  • 做网站建设公司怎么选百度商家怎么入驻
  • 怎么做诈骗网站吗头条今日头条新闻
  • 做营销网站建设价格一站式网站建设
  • 网站 网站建设定制关键时刻
  • 有什么好的网站网络建站公司
  • 高职院校高水平专业建设网站阿里巴巴国际站
  • 中国联合网络通信有限公司seo网站建设优化
  • 成都网站开发工资上海搜索推广
  • 给网站做路由一键关键词优化
  • 信用网站建设成效宁波百度关键词推广
  • 福州做网站网站seo外链建设
  • 网站产品推广制作黑河seo
  • 兼职做视频的网站谷歌seo视频教程
  • 投融网站建设方案aso平台
  • 仿腾讯游戏网站源码最佳bt磁力搜索引擎
  • 成都如何做网站最新新闻播报
  • 网站如何做关键词优化aso优化运营
  • 网站建设整体流程国内十大搜索引擎
  • 多终端网站开发seo优化快速排名