Comments (8)
Checking the comments here might be help:
socket.io/socket/broadcast-operator.go
Lines 143 to 154 in f688afa
from socket.io.
@zishang520 最近遇到个bug,但不确定是不是服务端的,表现为客户端收不到服务端发的消息,并且发生这种情况时,客户端会显示websocket断开过,后面好像是有重连,但丢失的消息就这样没了~ 客户端就是浏览器,也就是官方的js客户端
from socket.io.
@zishang520 这段代码之前有看到过,但是还是不确定这个err具体是什么。只有使用了timeout,err才有意义吗?或者说这个err只有超时才触发吗?如果不使用timeout,是不是意味着永远不会触发err,只会让代码卡在那,永远不返回?
from socket.io.
@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 这段代码之前有看到过,但是还是不确定这个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 这段代码之前有看到过,但是还是不确定这个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 is0
. - If you use
client.Emit("event", func([]any, error) {})
, only oneack
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.
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.
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 withclient.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)
- please add example list ,for example "gin", or export a socketio serverMux HOT 5
- how to use middle in Use funtion, stop this downward bubbling or next HOT 3
- 什么时候出4.6兄台 持支持支 HOT 3
- Any example ? HOT 3
- Benchmarking HOT 3
- Is *socket.Server Emit() safe for concurrent use? HOT 1
- Start https socket server HOT 1
- 怎么添加这个库为依赖 HOT 5
- How to get the clients or one of them HOT 2
- Does this project have Discord or Telegram group? HOT 1
- Golang client HOT 6
- 如何实现回调功能 HOT 6
- Possible to Ack incomming client EmitWithAck messages? HOT 1
- how to use on echo web freamwork HOT 2
- Nothing, absolutely nothing. works. Not even the default samples.
- Do you mind looking into Fiber adaptor for net/http interface to make this library work with fiber applications? HOT 4
- EmitwithAck never listens for the callback from the client so it always timed out HOT 6
- how to fetch /socket.io/socket.io.js ? HOT 3
- 请问socketio的reconnect机制到底啥玩意 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io.