-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]: 请教一下关于v2版本TCP粘包的问题 #495
Labels
help wanted
Extra attention is needed
question
Further information is requested
waiting for response
waiting for the response from commenter
Comments
devzwy
added
help wanted
Extra attention is needed
question
Further information is requested
labels
Aug 24, 2023
@panjf2000 感谢回复,已经参考解码器实现了自己的粘包功能。但是在Windows和Linux平台测试时发现了端口占用导致段时间内无法重新启动监听的问题,在Mac平台下是正常的。
复现流程:启动 func (cm *ConnectManager) StartGateway() {
logger.Printf("启动中...")
gConfig := config.GetConfig()
// 启动线路、启动安全验证
for _, gameLineData := range gConfig.GameLineConfig.Lines {
go cm.start(gameLineData)
}
go cm.start(gConfig.AAAConfig.Aaa)
// 创建一个信号通道
signalCh := make(chan os.Signal, 1)
// 监听指定的信号,例如 SIGINT(Ctrl+C)和 SIGTERM
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
// 阻塞等待信号
<-signalCh
// 停止监听
cm.stopGateway()
// 断开数据库链接
UnInitDB()
logger.Infof("网关已退出完成")
} func (cm *ConnectManager) start(config beans.PortConfigBean) {
server := &GatewayServer{
PortConfig: config,
}
cm.gatewayServices = append(cm.gatewayServices, server)
logger.Debugf("启动 %s (%d)", config.Name, config.ProxyPort)
err := gnet.Run(server, fmt.Sprintf("tcp://:%d", server.PortConfig.ProxyPort), func(opts *gnet.Options) {
opts.TCPNoDelay = gnet.TCPNoDelay
opts.Multicore = true
opts.SocketRecvBuffer = 1024 * 1024
opts.SocketSendBuffer = 1024 * 1024
})
if err != nil {
logger.Fatalf("%s(%d)启动失败,%s", config.Name, config.ProxyPort, err.Error())
}
} func (cm *ConnectManager) stopGateway() {
for _, player := range cm.connections {
player.sendCenterTip("#Y服务器断开链接", false)
player.ClientConn.Close()
player.ServerConn.Close()
}
for _, server := range cm.gatewayServices {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
logger.Debugf("关闭%s(%d)", server.PortConfig.Name, server.PortConfig.ProxyPort)
server.Engine.Stop(ctx)
}
} 期待大佬回复。 |
可以看这里 #485 (comment) |
感谢。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
help wanted
Extra attention is needed
question
Further information is requested
waiting for response
waiting for the response from commenter
Actions I've taken before I'm here
Questions with details
请教下这里会有粘包问题出现,读取到的
data
不全,用咱们gnet
框架需要手动处理粘包吗?有没有类似
Netty
框架的socketChannel.pipeline().addLast("decoder", LengthFieldBasedFrameDecoder(1024 * 1024, 8, 2))
这样的神器可以使用?我看其他的问题中似乎是v1版本的解码器的概念,在V2版本中似乎没有发现。我是go的小白,还望大佬不吝赐教。
我当前使用的版本是:
github.com/panjf2000/gnet/v2 v2.3.1
Code snippets (optional)
The text was updated successfully, but these errors were encountered: