jannal 2015-02-09
个人开发的手游服务器,现在开源出来,觉得好用就拿去用吧!后面会陆续更新维护。
项目地址:https://github.com/coder-leehui/lightning4j
一个基于Netty网络库的java服务端轻量级开发框架,用于快速开发手游,页游等服务端程序,使用WebSocket通信协议,支持mysql,redis,连接池,全局定时任务,心跳检测,可配置逻辑处理线程等,使用简单,部署方便。
新建一个maven project或在已有project中新建一个maven module,编辑pom.xml中的依赖包:
<dependencies> <dependency> <groupId>netty</groupId> <artifactId>netty</artifactId> <version>4.0.25.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.30</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.6</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.3</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> <dependency> <groupId>com.hql</groupId> <artifactId>lightning4j</artifactId> <version>1.0.0</version> </dependency> </dependencies>
ServerInit.getInstance().initConfPath("conf");
启动代码示例:
public class Server { public void run() throws Exception { ServerInit.getInstance().initConfPath("conf"); ServerInit.getInstance().initLog4j(); ServerInit.getInstance().initGameWorkers(); GameBoss.getInstance().boot(new GameUpProcessor() { @Override public void process(GameUpBuffer buffer) { GameWorkerManager.getInstance().pushDataToWorker(buffer); } }); } public static void main(String[] args) throws Exception { GameHandlerManager.getInstance().register(HandlerTest.class, "test"); GameHandlerManager.getInstance().register(DisconnectHandlerTest.class, "onDisconnect"); new Server().run(); } }
Apache License Version 2.0 see http://www.apache.org/licenses/LICENSE-2.0.html