lonng / nano Goto Github PK
View Code? Open in Web Editor NEWLightweight, facility, high performance golang based game server framework
License: MIT License
Lightweight, facility, high performance golang based game server framework
License: MIT License
Can you provide an example of the following cluster, THKS!
Cannot send messages larger than 2048 bytes.
Sending a message greater than 2048 results in an error, It's pretty certain。
buf := make([]byte, 2048) Unable to read the full message causing an error
This code needs to be modified to read all the message contents at once.
type RoomService struct {
component.Base
group *nano.Group
}
func newRoomService() *RoomService {
return &RoomService{
group: nano.NewGroup("all-users"),
}
}
比如这个服务多开几个,客户端连接分散这些服务,无法统一收到消息,这个怎么处理呢?
@lonng 集群模式下,session如何传递。 请求经过网关,网关通过RPC请求应用服务,session如何传递到应用服务
how implement nano with fasthttp?
rpc的实现相当于notify
func (a *agent) RPC(route string, v interface{}) error {
if a.status() == statusClosed {
return ErrBrokenPipe
}
data, err := message.Serialize(v)
if err != nil {
return err
}
msg := &message.Message{
Type: message.Notify,
Route: route,
Data: data,
}
a.rpcHandler(a.session, msg, true)
return nil
}
希望返回interface, err := a.rpcHandler(a.session, msg, true), 这个interface可以转成需要的类型,不知道大家怎么处理的??
chat 启动之后 http://localhost:3250/web/ 404 page not found in you
示例网关节点服务A:
err := s.RPC("TopicService.NewUser", request)
fmt.Println(err,"-------------------err")
if err != nil {
return errors.Trace(err)
}
Master节点服务B:
func (ts *TopicService) NewUser(s *session.Session, msg *protocol.NewUserRequest) error {
fmt.Println("---------------NewUser err")
return errors.Trace(errors.New("------------------123 err return"))
问题:服务B不管是关闭进程还是正常返回错误,服务A的s.RPC调用后err永远是nil
Hey,
I did a lot of benchmarks between nano and pomelo
nano wins every time.
seems golang is a much better choice for server side then javascript(who knew ;-) )
so I'm looking to move my server side project to nano
if I'll find any bugs I will report them or try to contribute fixes.
though I have a question when route compression will be implemented,
as it's pretty important and I only saw test code for it
In Get Started the following methods are undefined: OnSessionClosed, Register, SetSerializer, EnableDebug.
undefined: nano.OnSessionClosed
undefined: nano.Register
undefined: nano.SetSerializer
undefined: nano.EnableDebug
Then the example uses methods from both chat and cluster packages without import them.
请问未来是否会支持KCP协议?
chat中的
mgr.rooms[testRoomID] = room
不会有并发安全问题吗?
当需要水平扩展 Gate时,无法保证 session id 全局唯一。
当前实现方式是依据 session id 标记 session 资源。
当出现 CloseSession 的时候,如果不同的用户出现相同的 sessionId, 是否会导致 close 误伤?
经测试 相同的sessionId 确实存在。
当初要采用 session id, 而不是采用 uid 方式关联,是基于什么思考?
有其他方式可以绕开这一问题吗?
Why rpc function is a method of session struct, apparently it's completely independent from the session instance it's called from.
package main
import (
"errors"
"fmt"
"sync/atomic"
"time"
)
type test struct {
status int32
chDie chan struct{}
}
func (t *test) Close() error {
if atomic.LoadInt32(&t.status) > 0 {
return errors.New("closed test")
}
// wait another gorontine enter block
time.Sleep(time.Second)
atomic.StoreInt32(&t.status, 1)
close(t.chDie)
return nil
}
func main() {
fmt.Println("Hello, 世界")
t := &test{chDie: make(chan struct{})}
go t.Close()
go t.Close()
time.Sleep(3 * time.Second)
}
Session.Close
will occur the same problem show in above.
How to monitor the client to actively disconnect????
I've read that cockroachdb uses gogoprotubuf in their database for speed
it won the benchmark test
https://github.com/alecthomas/go_serialization_benchmarks
and I think it will work well with nano
https://github.com/gogo/protobuf
还有是否有多个连接使用一个grpc.ClientConn 的问题?难道是我没看懂代码?
Before asking a question, make sure you have:
What is the cluster restart sequence after a code change?
Does it support independent restart?
The problem currently encountered is that the session is not synchronized after restarting a service alone.
✅Searched existing Stack Overflow questions.
✅Googled your question.
✅Searched open and closed GitHub issues
Hi.
I wish there were more complicated examples and full working ones. like a simple game with simple authentication gateway.
it's a little confusing for me.
how to have authentication gate?
Before asking a question, make sure you have:
安卓和IOS可以使用promelo的客户端源码连接nano服务器吗?
https://github.com/NetEase/pomelo/wiki/pomelo%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%BC%80%E5%8F%91
像断电断网这种情况客户端没有发出任何断开连接的消息,服务端好像会一定时间后检测到连接的异常,会删除session,但是如果还有一些其他的清理操作应该怎么做呢?
**/github.com/lonnng/nano/app.go:120: Upgrade failure, URI=/favicon.ico, Error=websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header
how to solve the problem
客户端文档是直接用pomelo的客户端sdk文档吗?
Hi,
if err := s.RPC("TopicService.NewUser", request); err != nil {
return errors.Trace(err)
}
above code is in cluster example.
How can i check TopicService.NewUser
is success or error.
Currenty error is traced only when the TopicService down
thank you.
Hello There!
In the online Gaming Industry, Unity has a strong hold for frontend.
Do you think having Unity Demo under example will attract more contributors in community and gain attention on people in the industry?!
Before asking a question, make sure you have:
In case i want to develop multiplayer shooter/
The lastAt of agent is simultaneous reading and writing in two goroutines ( respectively in nano's reading and writing goroutines ), which means data race.
这个是啥问题,go run main.go
../../pkg/mod/github.com/lonnng/[email protected]/agent.go:31:2: use of internal package github.com/lonng/nano/internal/codec not allowed
../../pkg/mod/github.com/lonnng/[email protected]/agent.go:32:2: use of internal package github.com/lonng/nano/internal/message not allowed
../../pkg/mod/github.com/lonnng/[email protected]/agent.go:33:2: use of internal package github.com/lonng/nano/internal/packet not allowed
package main
import (
"fmt"
"log"
"net/http"
"github.com/lonnng/nano"
"github.com/lonnng/nano/component"
"github.com/lonnng/nano/serialize/json"
"github.com/lonnng/nano/session"
)
type (
// define component
Room struct {
component.Base
group *nano.Group
}
// protocol messages
UserMessage struct {
Name string `json:"name"`
Content string `json:"content"`
}
NewUser struct {
Content string `json:"content"`
}
AllMembers struct {
Members []int64 `json:"members"`
}
JoinResponse struct {
Code int `json:"code"`
Result string `json:"result"`
}
)
func NewRoom() *Room {
return &Room{
group: nano.NewGroup("room"),
}
}
func (r *Room) AfterInit() {
nano.OnSessionClosed(func(s *session.Session) {
r.group.Leave(s)
})
}
// Join room
func (r *Room) Join(s *session.Session, msg []byte) error {
s.Bind(s.ID()) // binding session uid
s.Push("onMembers", &AllMembers{Members: r.group.Members()})
// notify others
r.group.Broadcast("onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())})
// new user join group
r.group.Add(s) // add session to group
return s.Response(&JoinResponse{Result: "sucess"})
}
// Send message
func (r *Room) Message(s *session.Session, msg *UserMessage) error {
return r.group.Broadcast("onMessage", msg)
}
func main() {
nano.Register(NewRoom())
nano.SetSerializer(json.NewSerializer())
nano.EnableDebug()
log.SetFlags(log.LstdFlags | log.Llongfile)
http.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir("web"))))
nano.SetCheckOriginFunc(func(_ *http.Request) bool { return true })
nano.Listen(":3250", nano.WithIsWebsocket(true))
}
Handshake Package 中如何自定义握手数据验证
client demo和文档中有出现
{ "sys": { "version": "1.1.1", "type": "js-websocket" }, "user": { // Any customized request data } }
的描述
code - 握手响应的状态码。目前的取值:200代表成功,500为处理用户自定义握手流程时失败,501为客户端版 本号不符合要求。
sys.heartbeat - 可选,心跳时间间隔,单位为秒,没指定表示不需要心跳。
dict - 可选,route字段压缩的映射表,没指定表示没有字典压缩。
protos - 可选,protobuf压缩的数据定义,没有表示没有protobuf压缩。
user - 可选,用户自定义的握手数据,没有表示没有用户自定义的握手数据。
服务端关于user的数据如何验证?
我想把nano application 做成分散式的架構,但是想要共用session,請問能加上這方面的支持嗎?
Please answer these questions before submitting your issue. Thanks!
I Tried to run the chat example, using go run main.go
but it wasn't possible because of the nano.ListenWS
is no longer available.
Chat example running
./main.go:153:2: undefined: nano.ListenWS
nano
I cloned the repository at 2019-08029, not sure the version.
@lonng 消息默认转发给全局携程处理,如何根据业务请求自定义携程。有没有示例
Hi,
thanks for great framework.
Can you give me a golang client example.
thank you.
Hi
I'm just wondering if there is a Go client example (not HTML+JS) anywhere?
Thanks
Ken
gate进程
master进程
chat进程
分别能承受多少人同时在线?
现在的master chat gate 几乎都有逻辑代码。。
master 职能到底是干嘛的?
gate 不应该只负责对外链接吗?
chat 不应该处理全部逻辑吗?
设计思路混乱
How to realize session sharing in cluster mode
Before asking a question, make sure you have:
// Decode decode the network bytes slice to packet.Packet(s)
// TODO(Warning): shared slice
func (c *Decoder) Decode(data []byte) ([]*packet.Packet, error)
1.我想让不同的comment在不同的goroutine中运行,但是
只看到了handler中的localProcess的注释和schd的定义,
但是没有example,希望可以写个eample演示一下.万分感谢
2.看了下关于分布式的实现,很想知道为什么不用成熟的etcd,consul方案,需要自己实现一下注册中心呢?
之前看skynet,云风大大博客里面写了skynet项目的设计综述,对项目理解非常有帮助。不知道作者有没有写过相关文档可以看一下
The English in the documentation is very not good. As a beginner to golang and nano, I'm having a lot of trouble understanding it.
Eg;
While handling a message, the handler will receive two arguments, session corresponding a client and a message is the payload of this request that unmarshals by nano automatically.
While handling a message, the handler will receive two arguments, a session id corresponding to a client and a content indicating the payload of the request....
Okay? I had to read through it several times to understand that far.
However, you lost me at unmarshals.
If anyone knows both English and go and nano and can go through the docs it would be a great help...
目前看范例上的rpc只能透过session进行rpc行為,
请问nano有办法让server间可以直接rpc,
实现像pomelo的remote rpc机制吗?谢谢。
// Kick represents a kick off packet
Kick = 0x05 // disconnect message from server
请问这个数据包类型并没有实现吗?
源码没有一个地方调用过该类型。应该需要额外加一个类似s.Response接口来处理Kick类型的数据包吧。
客户端虽然有这个数据包类型的定义接收,但是服务端没有实现这个数据包类型的封装?
handlers[Package.TYPE_KICK] = onKick;
Since nano did not implement SESSION-UID binding broadcast like pomelo, I think that nano should add uid with SessionID in gRPC request so that user could maintain unique sid-uid binding at frontend named "connector"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.