Gorilla WebSocket与golang.org/x/net/websocket的比较

huangapple go评论84阅读模式
英文:

Gorilla WebSocket compared with golang.org/x/net/websocket

问题

根据Gorilla Websockets Project的说法,使用golang.org/x/net/websocket无法发送ping和pong。然而,在golang.org/x/net/websocket的项目页面上有以下说明:

> Package websocket实现了WebSocket协议的客户端和服务器,该协议在RFC 6455中有详细规定。

我有点困惑。golang.org/x/net/websocket实现了RFC 6455,但无法发送控制帧(cancel、ping、pong),尽管在RFC 6455 - Section Control Frames中有明确规定。

那么,如果我使用golang.org/x/net/websocket包会发生什么呢?连接会在超时后中断吗?换句话说,在这里如何确保连接不会中断。

英文:

According Gorilla Websockets Project it is not possible to send pings and pongs using golang.org/x/net/websocket. At the same time, the following is on the project page of golang.org/x/net/websocket:

> Package websocket implements a client and server for the WebSocket protocol as specified in RFC 6455.

I am a little confused. golang.org/x/net/websocket implements RFC 6455 but can not send control frames (cancel, ping, pong) although this is specified in RFC 6455 - Section Control Frames

So what will happen if I use golang.org/x/net/websocket package. Will the connection abort after a timeout? In other words, how is it ensured here that the connection does not break off.

答案1

得分: 8

根据Gorilla Websockets项目的说法,使用golang.org/x/net/websocket无法发送ping和pong。

Gorilla的README中有所不同的说明。它说golang.org/x/net包无法发送ping或接收pong。但它并没有说该包不会发送pong。

golang.org/x/net包会自动响应从对等方接收到的ping,向对等方发送pong,就像Gorilla包一样。这两个包都可以与使用ping和pong保持连接的对等方正常工作。

使用golang.org/x/net/websocket包的应用程序无法使用ping和pong来保持连接。无法发送ping,也无法检测到是否接收到pong。

英文:

> According Gorilla Websockets Project it is not possible to send pings and pongs using golang.org/x/net/websocket

The Gorilla README says something different. It says that the golang.org/x/net package cannot send a ping or receive a pong. It does not say that the package will not send a pong.

The golang.org/x/net package automatically responds to a ping received from the peer by sending a pong to the peer, as does the Gorilla package. Both packages work correctly with a peer that's using ping and pongs to keep the connection alive.

An application that uses the golang.org/x/net/websocket package cannot employ pings and pongs to keep the connection alive. There's no way to send the ping. There's no way to detect that the pong was received.

huangapple
  • 本文由 发表于 2015年7月7日 16:30:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/31263519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定