Skip to content
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

Update connection.go #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions znet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (c *Connection) StartReader() {
zlog.Ins().ErrorF("read msg head [read datalen=%d], error = %s", n, err)
return
}
fmt.Println("-------------------------------------------buffer----------------------------", n)
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))

// If normal data is read from the peer, update the heartbeat detection Active state
Expand All @@ -235,14 +236,28 @@ func (c *Connection) StartReader() {
// Deal with the custom protocol fragmentation problem, added by uuxia 2023-03-21
// (处理自定义协议断粘包问题)
if c.frameDecoder != nil {
fmt.Println("----------------------------------------------------Came Here---------------------------------------------------")
// Decode the 0-n bytes of data read
// (为读取到的0-n个字节的数据进行解码)
bufArrays := c.frameDecoder.Decode(buffer[0:n])
data := hex.EncodeToString(buffer[0:n])
fmt.Println("before the data is", data)
contains := strings.HasPrefix(data, "00000001000000b1")
if !contains {
data = "00000001000000b1" + data
}
fmt.Println("after the data is", data)
byteDate, err := hex.DecodeString(data)
if err != nil {
fmt.Println("error while byte conversion", err)
continue
}
bufArrays := c.frameDecoder.Decode(byteDate)
if bufArrays == nil {
fmt.Println("----------------------------bufarray is empty--------------------------")
continue
}
for _, bytes := range bufArrays {
//zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(bytes))
zlog.Ins().DebugF("read buffer ------------------------------------>%s \n", hex.EncodeToString(bytes))
msg := zpack.NewMessage(uint32(len(bytes)), bytes)
// Get the current client's Request data
// (得到当前客户端请求的Request数据)
Expand Down