# nano **Repository Path**: ycb-debug/nano ## Basic Information - **Project Name**: nano - **Description**: 轻量、便捷、高性能的基于golang的游戏服务器框架,nano-server基于nano实现 - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-01-26 - **Last Updated**: 2025-01-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Nano [![Build Status][1]][2] [![GoDoc][3]][4] [![Go Report Card][5]][6] [![MIT licensed][7]][8] [1]: https://travis-ci.org/lonng/nano.svg?branch=master [2]: https://travis-ci.org/lonng/nano [3]: https://godoc.org/github.com/lonng/nano?status.svg [4]: https://godoc.org/github.com/lonng/nano [5]: https://goreportcard.com/badge/github.com/lonng/nano [6]: https://goreportcard.com/report/github.com/lonng/nano [7]: https://img.shields.io/badge/license-MIT-blue.svg [8]: LICENSE Nano 是一个易于使用、快速、轻量级的 Go 游戏服务器网络库。它提供了核心网络架构和一系列工具和库,可以帮助开发人员消除常见底层逻辑的枯燥重复工作。nano 的目标是通过消除花费时间进行重复的网络相关编程来提高开发效率。 Nano 是为各种规模的服务器端应用程序而设计的,例如实时游戏、社交游戏、手机游戏等。 ## 如何用“Nano”构建系统 #### “Nano” 应用程序是什么样的? 最简单的 “nano” 应用程序,如下图所示,您可以通过组合不同的组件来制作强大的应用程序。 ![Application](media/application.png) 实际上,nano 应用是[组件(Component) ](./docs/get_started.md#component) 的集合,而一个 组件(Component) 是一组  [(处理器)Handler](./docs/get_started.md#handler), 的集合,一旦你将一个 Component 注册到 nano,nano 就会将所有可以转换为 Handler 的方法注册到 nano 服务容器中。服务通过 Component.Handler 进行访问,当客户端请求时,Handler 会被调用。Handler 在处理消息时会收到两个参数: - `*session.Session`: 对应发起此请求或通知的客户端。 - `*protocol.FooBar`: 请求的 payload。 当你处理完你的逻辑后,你就可以通过session.Response(payload)和session.Push('eventName', payload)来响应或者推送消息给客户端,或者在收到一些意外的数据时返回错误。 #### 如何用 Nano 构建分布式系统 Nano 内置分布式系统解决方案,让您轻松创建分布式游戏服务器。 另请: [分布式聊天演示](https://github.com/lonng/nano/tree/master/examples/cluster) Nano 将保持简单,但您可以在组件中执行任何操作并实现所需的目标。您可以启动一组 Nano 应用程序作为代理,将消息分发到后端服务器。 #### 如何执行异步任务 ```go 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 - English + [How to build your first nano application](./docs/get_started.md) + [Route compression](./docs/route_compression.md) + [Communication protocol](./docs/communication_protocol.md) + [Design patterns](./docs/design_patterns.md) + [API Reference(Server)](https://godoc.org/github.com/lonnng/nano) + [How to integrate `Lua` into `Nano` component(incomplete)](.) - 简体中文 + [如何构建你的第一个nano应用](./docs/get_started_zh_CN.md) + [路由压缩](./docs/route_compression_zh_CN.md) + [通信协议](./docs/communication_protocol_zh_CN.md) + [API参考(服务器)](https://godoc.org/github.com/lonnng/nano) + [如何将`lua`脚本集成到`nano`组件中(未完成)](.) ## Resources - Javascript + [nano-websocket-client](https://github.com/lonnng/nano-websocket-client) + [nano-egret-client](https://github.com/lonnng/nano-egret-client) - Demo + [Implement a chat room in 100 lines with nano and WebSocket](./examples/demo/chat) + [Tadpole demo](./examples/demo/tadpole) + [四川麻将, 血战到底(三人模式/四人模式)完整项目实例](https://github.com/lonnng/nanoserver) ## Community - QQGroup: [289680347](https://jq.qq.com/?_wv=1027&k=4EMMaha) - Reddit: [nanolabs](https://www.reddit.com/r/nanolabs/) ## Successful cases - [空来血战](https://fir.im/tios) ## Go version `> go1.8` ## Installation ```shell go get github.com/lonng/nano # dependencies go get -u github.com/golang/protobuf go get -u github.com/gorilla/websocket ``` ## Benchmark ```shell # 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/io go test -v -tags "benchmark" ``` ## License [MIT License](./LICENSE)