I am trying to learn about websockets, and I am not sure I understand what exactly Upgrader does in gorilla/websockets.
http://www.gorillatoolkit.org/pkg/websocket#Upgrader
Can someone please explain in simple terms what exactly the buffer sizes mean?
WebSocket is a communications protocol for a persistent, bi-directional, full duplex TCP connection from a user's web browser to a server. A WebSocket connection is initiated by sending a WebSocket handshake request from a browser's HTTP connection to a server to upgrade the connection.
In WebSocket, communication occurs at both ends, which makes it a faster protocol. In HTTP, the connection is built at one end, making it a bit sluggish than WebSocket. WebSocket uses a unified TCP connection and needs one party to terminate the connection. Until it happens, the connection remains active.
The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
The wss protocol establishes a WebSocket over an encrypted TLS connection, while the ws protocol uses an unencrypted connection. At this point, the network connection remains open and can be used to send WebSocket messages in either direction.
The Upgrader.Upgrade method upgrades the HTTP server connection to the WebSocket protocol as described in the WebSocket RFC. A summary of the process is this: The client sends an HTTP request requesting that the server upgrade the connection used for the HTTP request to the WebSocket protocol. The server inspects the request and if all is good the server sends an HTTP response agreeing to upgrade the connection. From that point on, the client and server use the WebSocket protocol over the network connection.
Applications use Upgrader fields to specify options for the upgrade operation.
The WebSocket connection buffers reads and writes to the underlying network connection. The ReadBufferSize and WriteBufferSize specifies the size of these buffers. It's usually best to use the default size by setting ReadBufferSize and WriteBufferSize to zero. Larger buffer sizes take more memory. Smaller buffer sizes can result in more calls to the underlying network connection. The buffer sizes do not limit the size of a message that can be read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With