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

一些给后来的人的建议 #15

Open
mofadeyunduo opened this issue Apr 22, 2020 · 3 comments
Open

一些给后来的人的建议 #15

mofadeyunduo opened this issue Apr 22, 2020 · 3 comments

Comments

@mofadeyunduo
Copy link

mofadeyunduo commented Apr 22, 2020

  • 这个版本依赖的类库是 Socket.IO 1.x 的类库,我本人没用 Socket.IO 1.x,不知道能不能使用,不过我肯定的是 Socket.IO 2.x 是有问题的
  • 我这里用 Socket.IO 2.x,参考了 https://socket.io/docs/internals/#socket-io-client 的说明,改了些代码,目前测试可用的,但我不确定是否稳定用于生产(因为我们的需求比较简单)
  • 即使是 1.x,client_conn.go pingLoop 那段代码也是有问题的
@mofadeyunduo
Copy link
Author

func (c *clientConn) pingLoop() {
	lastPing := time.Now()
	lastTry := lastPing
	for {
		now := time.Now()
		pingDiff := now.Sub(lastPing)
		tryDiff := now.Sub(lastTry)
		select {
		case ok := <-c.pingChan:
			if !ok {
				return
			}
			fmt.Println("ping chan receive data")
			lastPing = time.Now()
			lastTry = lastPing
		case <-time.After(c.pingInterval - tryDiff):
			fmt.Println("ping again")
			c.writerLocker.Lock()
			if w, _ := c.getCurrent().NextWriter(message.MessageText, parser.PING); w != nil {
				writer := newConnWriter(w, &c.writerLocker)
				writer.Close()
			} else {
				c.writerLocker.Unlock()
			}
			lastTry = time.Now()
		}
		case <-time.After(c.pingTimeout - pingDiff):
			c.Close()
			return
		}
	}
}

Socket.IO 默认 pingInterval 为 25s,pingTimeout 5s,如果 pingInterval > pingTimeout 会导致强制销毁 Socket.IO 链接,我觉得这个是有问题的

@mofadeyunduo
Copy link
Author

mofadeyunduo commented Apr 23, 2020

我改了下他上面的问题,并且魔改了一些东西,Socket.IO 2.x 也可以使用,可以参考 go-socket.io-client,有问题提 Issue

@hlbbt
Copy link

hlbbt commented Nov 10, 2022

我改了下他上面的问题,并且魔改了一些东西,Socket.IO 2.x 也可以使用,可以参考 go-socket.io-client,有问题提 Issue

请问基于https地址的socket是否支持,我自己测试是不支持的。
image
显示超时,我使用nodejs是可以实现的,基于socket.io 1.7.4版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants