Gorilla WebSockets是否支持不同连接的并发读写?

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

Do Gorilla websockets support concurrent read/writes for different connections?

问题

我正在处理一个Go应用程序,它接受来自不同客户端的WebSocket连接。我使用了Gorilla WebSocket库。根据文档页面这里的说明,它说不允许并发的读写操作。

但它并没有明确说明是整个连接都不支持并发,还是只针对特定客户端不支持并发。

也就是说,我知道不能同时读写同一个连接。但是可以同时从一个连接读取并写入另一个连接,这样可以吗?

有人可以帮助我理解这些基础知识吗?非常感谢任何帮助。

英文:

I am working on a Go application which accepts websocket connections from different client. I have used the Gorilla websocket library.
From the documentation page here,
It says, no concurrent read/writes are permitted.

But it does not clearly say that wether concurrency is not at all supported throughout all the connections OR it is not supported only for that specific client.

That means - I know you can not read and write to same connection concurrently. But Concurrently read from one connection and write to another.
Is it allowed?

Can anyone help me in understanding this basics. Any help appreciated.

答案1

得分: 2

根据文档的说明:

> 连接支持一个并发读取器和一个并发写入器。

文档表示每个连接最多只能有一个读取器和一个写入器。换句话说,以下操作是不允许的:

  • 在同一连接上有两个或更多并发读取器。
  • 在同一连接上有两个或更多并发写入器。

该包中的并发限制允许以下操作:

  • 应用程序可以同时读取和写入同一连接(与问题中的断言相反)。
  • 应用程序可以同时从多个连接中读取,其中每个连接都有一个并发读取器。
  • 应用程序可以同时向多个连接写入,其中每个连接都有一个并发写入器。
  • 应用程序可以同时从一个连接读取并向另一个连接写入。一个连接有一个读取器,另一个连接有一个写入器。
英文:

The documentation says:

> Connections support one concurrent reader and one concurrent writer.

The documentation is saying that each connection can have at most one reader and one writer. To put this another way, the following operations are not allowed:

  • Two or more concurrent readers on the same connection.
  • Two or more concurrent writers on the same connection.

The concurrency restriction in the package allows for the following:

  • The application can concurrently read and write the same connection (contrary to the assertion in the question).
  • The application can read from multiple connections concurrently where each connection has one concurrent reader.
  • The application can write to multiple connections concurrently where each connection has one concurrent writer.
  • The application can concurrently read from one connection and write to another connection. One connection has a reader, the other connection has a writer.

huangapple
  • 本文由 发表于 2021年10月24日 04:05:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/69691654.html
匿名

发表评论

匿名网友

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

确定