Giter VIP home page Giter VIP logo

Comments (8)

zishang520 avatar zishang520 commented on June 24, 2024

Checking the comments here might be help:

// Adds a timeout in milliseconds for the next operation
//
// io.Timeout(1000 * time.Millisecond).Emit("some-event", func(args []any, err error) {
// if err != nil {
// // some clients did not acknowledge the event in the given delay
// } else {
// fmt.Println(args) // one response per client
// }
// })
//
// Param: timeout
func (b *BroadcastOperator) Timeout(timeout time.Duration) *BroadcastOperator {

from socket.io.

vipcxj avatar vipcxj commented on June 24, 2024

@zishang520 最近遇到个bug,但不确定是不是服务端的,表现为客户端收不到服务端发的消息,并且发生这种情况时,客户端会显示websocket断开过,后面好像是有重连,但丢失的消息就这样没了~ 客户端就是浏览器,也就是官方的js客户端

from socket.io.

vipcxj avatar vipcxj commented on June 24, 2024

@zishang520 这段代码之前有看到过,但是还是不确定这个err具体是什么。只有使用了timeout,err才有意义吗?或者说这个err只有超时才触发吗?如果不使用timeout,是不是意味着永远不会触发err,只会让代码卡在那,永远不返回?

from socket.io.

zishang520 avatar zishang520 commented on June 24, 2024

@zishang520 最近遇到个bug,但不确定是不是服务端的,表现为客户端收不到服务端发的消息,并且发生这种情况时,客户端会显示websocket断开过,后面好像是有重连,但丢失的消息就这样没了~ 客户端就是浏览器,也就是官方的js客户端

You can try enabling session:

// ...more
c := socket.DefaultServerOptions()
c.SetConnectionStateRecovery(&socket.ConnectionStateRecovery{})

httpServer := types.CreateServer(nil)
io := socket.NewServer(httpServer, c)

// ...more

from socket.io.

zishang520 avatar zishang520 commented on June 24, 2024

@zishang520 这段代码之前有看到过,但是还是不确定这个err具体是什么。只有使用了timeout,err才有意义吗?或者说这个err只有超时才触发吗?如果不使用timeout,是不是意味着永远不会触发err,只会让代码卡在那,永远不返回?

Yes, currently there are only timeout error messages. Regarding the logic of not setting a timeout, I will reply to you after confirmation.

from socket.io.

zishang520 avatar zishang520 commented on June 24, 2024

@zishang520 这段代码之前有看到过,但是还是不确定这个err具体是什么。只有使用了timeout,err才有意义吗?或者说这个err只有超时才触发吗?如果不使用timeout,是不是意味着永远不会触发err,只会让代码卡在那,永远不返回?

I've confirmed the Ack logic for the case where no timeout is set:

  • If you use Broadcast().Emit("event", func([]any, error) {}), it will almost certainly be considered a timeout because the default timeout is 0.
  • If you use client.Emit("event", func([]any, error) {}), only one ack function will be registered in the context. The default timeout will not be set, and the function will be destroyed when the client calls or disconnects.

from socket.io.

vipcxj avatar vipcxj commented on June 24, 2024

In my opinion, a timeout of 0 means that it will never time out, after all, a timeout of 0 is meaningless in practice.

Do you mean that Broadcast().Emit("event", func([]any, error) {}) is the wrong way to use it in practice? And with client.Emit("event", func([]any, error) {}) the ack won't be executed at all in the event of a timeout or disconnection. So in a nutshell ack must be executed in conjunction with a timeout or disconnection. So in summary ack must be used in conjunction with timeout, otherwise it's pointless?

from socket.io.

zishang520 avatar zishang520 commented on June 24, 2024

In my opinion, a timeout of 0 means that it will never time out, after all, a timeout of 0 is meaningless in practice.

Do you mean that Broadcast().Emit("event", func([]any, error) {}) is the wrong way to use it in practice? And with client.Emit("event", func([]any, error) {}) the ack won't be executed at all in the event of a timeout or disconnection. So in a nutshell ack must be executed in conjunction with a timeout or disconnection. So in summary ack must be used in conjunction with timeout, otherwise it's pointless?

Yes, it must be used together with timeout in broadcast, otherwise it is meaningless. The client is allowed not to set a timeout, This scenario is suitable for the client to handle some services with uncertain response time.

from socket.io.

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.