Giter VIP home page Giter VIP logo

Comments (10)

davyxu avatar davyxu commented on May 4, 2024

把你的测试的代码贴下

from cellnet.

davyxu avatar davyxu commented on May 4, 2024

都强制关进程了,连接断开过程是无法结束的,这种情况跟掐网线是一回事
游戏服务中会使用逻辑层的心跳超时解决这个问题

from cellnet.

molixiaoge avatar molixiaoge commented on May 4, 2024

客户端 chat client 代码如下

package main

import (
"bufio"
"github.com/davyxu/cellnet"
"github.com/davyxu/cellnet/examples/chat/proto/chatproto"
"github.com/davyxu/cellnet/socket"
"github.com/davyxu/golog"
"os"
"fmt"
"strings"
"time"
)
var log = golog.New("main")
func ReadConsole(callback func(string)) {
for {
text, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
break
}
text = strings.TrimRight(text, "\n\r ")
text = strings.TrimLeft(text, " ")
callback(text)
}
}

func main() {
queue := cellnet.NewEventQueue()
queue.EnableCapturePanic(false)
var m1 map[cellnet.Peer]cellnet.Peer
m1=make(map[cellnet.Peer]cellnet.Peer)
for i := 0; i < 70000; i++ {
time.Sleep(1000000)
peer := socket.NewConnector(queue).Start("10.0.0.228:8801")
peer.(socket.Connector).SetAutoReconnectSec(2)
peer.SetName("client")
m1[peer]=peer
cellnet.RegisterMessage(peer, "chatproto.ChatACK", func(ev *cellnet.Event) {
msg := ev.Msg.(*chatproto.ChatACK)
log.Infof("sid%d say: %s", msg.Id, msg.Content)
})
}
queue.StartLoop()
ReadConsole(func(str string) {
for k, v := range m1 {
fmt.Printf("%s=%d;", k, v)
v.(socket.Connector).DefaultSession().Send(&chatproto.ChatREQ{
Content: str,
})
break
}
})
}

server代码 不变,但是如果我在server里加上这样的代码

cellnet.RegisterMessage(peer, "coredef.SessionClosed", func(ev *cellnet.Event) {

	msg := ev.Msg.(*coredef.SessionClosed)

	log.Debugln("连接关闭!", msg.Result)


})

则不会出现资源泄漏情况

from cellnet.

davyxu avatar davyxu commented on May 4, 2024

只是一个关闭通知就不会泄露?

from cellnet.

molixiaoge avatar molixiaoge commented on May 4, 2024

我测试的情况是这样的,理论上如果我直接关闭chat client程序,这时候系统会通知server socket已经关闭。你说的拔网线情况属于消息丢失,这时候才需要加心跳。

from cellnet.

davyxu avatar davyxu commented on May 4, 2024

你不是说的是强制关闭客户端么? 这个和拔网线类似的

from cellnet.

molixiaoge avatar molixiaoge commented on May 4, 2024

在内网做的测试,我关客户端的话这时候server端有打印收到socket close消息,但是有1000个左右的socket永远无法关闭了。也许是消息确实丢失了,那这里有什么业务内置心跳可用么?

from cellnet.

molixiaoge avatar molixiaoge commented on May 4, 2024

我之前做的测试内网情况下(c++),这种泄漏基本没有。刚刚又试了一下 3w多个连接永远无法关闭了.你说的也有道理,但是这里拔网线和关客户端肯定是有区别的。

from cellnet.

davyxu avatar davyxu commented on May 4, 2024

是的,C++我也没发现有这种问题,我最近查下,感谢测试

from cellnet.

davyxu avatar davyxu commented on May 4, 2024

强制关闭客户端时,tcp本身无法正常关闭,聊天客户端逻辑不会包含逻辑心跳检测,因此会有这个问题。游戏服务器中会添加心跳检测,非正常关闭时,超时检测到会清除socke的,所以这个不是cellnet处理的,应该由逻辑层完成。

from cellnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.