Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Necessary to Add Ack Mechanism To Websocket Server?

We are building a websocket server via golang+gin+json+gorilla websocket to push messages from server side to browser.

We plan to provide frontend with some subscription command, which means messages from server side will be sent to those users who subscribed target topic.

My confusion is whether we need add Ack mechanism here? For example, when client subscribe one topic, the server saved this mapping: user --> topic.

Is it necessary for the server to send a response for each subscription request to clients (Like that we do for an RPC request)? And how to do that? Below is my consumption

type MsgHeader struct {
    ReqId string  `json: reqId`
    Cmd   string  `json: cmd`

    // either of "req" or "rsp"
    // is it necessary to have this field???
    Type  string  `json: type`            
}

I mean the application level acknowledgement, like what we do for RPC requests. For RPC request, we send responses even when the response itself is empty, something like:

type SubscriptionRsp struct {
     Code int
     Msg  string
     Data interface{}
}
like image 535
Wallace Avatar asked Oct 30 '25 17:10

Wallace


1 Answers

No, it's not necessary.

The Websocket specs (RFC 6455) does not mandate this.

A data frame MAY be transmitted by either the client or the server at any time after opening handshake completion and before that endpoint has sent a Close frame

Nothing else about acknowledging messages is said in the Sending and Receiving Data section.

Therefore any ACK is entirely an implementation detail of your application. It may be useful if you develop a resilient client that retries failed messages, where "failed" could a message that is successfully sent to the server but not processed as expected.

like image 197
blackgreen Avatar answered Nov 02 '25 14:11

blackgreen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!