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

Time:10-25

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.

CodePudding user response:

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.
  • Related