Nano -- 轻量级、便利、高性能基于golang的游戏服务器框架

网友投稿 1837 2022-11-02

Nano -- 轻量级、便利、高性能基于golang的游戏服务器框架

Nano -- 轻量级、便利、高性能基于golang的游戏服务器框架

Nano is an easy to use, fast, lightweight game server networking library for Go. It provides a core network architecture and a series of tools and libraries that can help developers eliminate boring duplicate work for common underlying logic. The goal of nano is to improve development efficiency by eliminating the need to spend time on repetitious network related programming.

Nano was designed for server-side applications like real-time games, social games, mobile games, etc of all sizes.

How to build a system with Nano

What does a Nano application look like?

The simplest "nano" application as shown in the following figure, you can make powerful applications by combining different components.

In fact, the nano application is a collection of  Component , and a component is a bundle of  Handler, once you register a component to nano, nano will register all methods that can be converted to Handler to nano service container. Service was accessed by Component.Handler, and the handler will be called while client request. The handler will receive two parameters while handling a message:

*session.Session: corresponding a client that apply this request or notify.*protocol.FooBar: the payload of the request.

While you had processed your logic, you can response or push message to the client by session.Response(payload) and session.Push('eventName', payload), or returns error when some unexpected data received.

How to build distributed system with Nano

Nano contains built-in distributed system solution, and make you creating a distributed game server easily.

See: The distributed chat demo

The Nano will remain simple, but you can perform any operations in the component and get the desired goals. You can startup a group of Nano application as agent to dispatch message to backend servers.

How to execute the asynchronous task

func (manager *PlayerManager) Login(s *session.Session, msg *ReqPlayerLogin) error { var onDBResult = func(player *Player) { manager.players = append(manager.players, player) s.Push("PlayerSystem.LoginSuccess", &ResPlayerLogin) } // run slow task in new gorontine go func() { player, err := db.QueryPlayer(msg.PlayerId) // ignore error in demo // handle result in main logical gorontine nano.Invoke(func(){ onDBResult(player) }) } return nil}

Documents

EnglishHow to build your first nano applicationRoute compressionCommunication protocolDesign patternsAPI Reference(Server)How to integrate Lua into Nano component(incomplete) 简体中文如何构建你的第一个nano应用路由压缩通信协议API参考(服务器)如何将lua脚本集成到nano组件中(未完成)

Resources

Javascriptnano-websocket-clientnano-egret-client DemoImplement a chat room in 100 lines with nano and WebSocketTadpole demo四川麻将, 血战到底(三人模式/四人模式)完整项目实例

Community

QQGroup: 289680347Reddit: nanolabs

Successful cases

空来血战

Go version

> go1.8

Installation

go get github.com/lonng/nano# dependenciesgo get -u github.com/golang/protobufgo get -u github.com/gorilla/websocket

Benchmark

# Case: PingPong# OS: Windows 10# Device: i5-6500 3.2GHz 4 Core/1000-Concurrent   => IOPS 11W(Average)# Other: ...cd $GOPATH/src/github.com/lonng/nano/benchmark/iogo test -v -tags "benchmark"

License

MIT License

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:多么痛的领悟---关于RMB数据类型导致的元转分分转元的bug
下一篇:分享一种系统事故&问题处理反馈方式(COE)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~