Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit f4d5575

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: fixing content
1 parent f23d2da commit f4d5575

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

docs/core-concepts/websocket/index.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ keywords:
1414
description: What is a WebSocket?
1515
---
1616

17-
## What is a WebSocket?
17+
## What are WebSockets?
1818

19-
The `WebSocket` protocol, described in the specification [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455), provides a way to exchange data between browser and server via a persistent connection. The data can be passed in both directions as “packets”, without breaking the connection and the need of additional HTTP-requests.
19+
The `WebSocket` protocol, described in the specification [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455), provides a way to exchange data between the browser and the server via a persistent connection. The data can be passed in both directions as “packets” without breaking the connection or needing additional HTTP requests.
2020

2121
WebSocket is especially great for services that require continuous data exchange, e.g. real-time trading systems and so on.
2222

23-
## A Simple example
23+
## A simple example
2424

2525
To open a WebSocket connection, we need to create `new WebSocket` using the special protocol `ws`or `wss` in the url. Here is how you can do that in `JavaScript`:
2626

@@ -29,21 +29,21 @@ let socket = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1089');
2929
```
3030

3131
:::caution
32-
Always prefer `wss://`. The `wss://` protocol is not only encrypted, but also more reliable.
32+
Using `wss://` is always the better choice. The `wss://` protocol is not only encrypted, but also more reliable.
3333

34-
That’s because ws:// data is not encrypted, visible for any intermediary. Old proxy servers do not know about WebSocket, they may see “strange headers and abort the connection.
34+
On the other hand, the `ws://` data is not encrypted and can be visible to intermediaries. Old proxy servers may encounter "strange" headers and terminate the connection.
3535

36-
On the other hand, `wss://` is WebSocket over TLS, (same as HTTPS is HTTP over TLS), the transport security layer encrypts the data at the sender and decrypts it at the receiver. So data packets are passed encrypted through proxies. They can’t see what’s inside and let them through.
36+
`wss://` stands for WebSocket over TLS, similar to how HTTPS is HTTP over TLS. With the transport security layer, data is encrypted by the sender and decrypted by the receiver. This means that encrypted data packets can successfully pass through proxies without being inspected.
3737
:::
3838

39-
Once the socket is created, we should listen to events on it. There are totally 4 events:
39+
Once the socket is created, we should listen to events on it. There are 4 events altogether:
4040

41-
- openconnection established,
42-
- messagedata received,
43-
- error – WebSocket error,
44-
- closeconnection closed.
41+
- OpenConnection established
42+
- MessageData received
43+
- Error – WebSocket error
44+
- CloseConnection closed
4545

46-
And if we’d like to send a message then socket.send(data) will do that.
46+
Sending a message can be done via socket.send(data).
4747

4848
Here’s an example in `JavaScript`:
4949

@@ -79,17 +79,18 @@ socket.onerror = function (error) {
7979

8080
## Why do we need WebSockets and when should we avoid them?
8181

82-
WebSocket are an essential client-server communication tool and one needs to be fully aware of its utility and avoid scenarios to benefit from its utmost potential. It’s explained extensively in the next section.
82+
WebSocket are an essential client-server communication tool. To benefit the most from their potential, it's important to understand how they can be helpful and when it's best to avoid using them. It’s explained extensively in the next section.
8383

8484
Use WebSocket When You Are:
8585

86-
1. ‍Developing real-time web application
87-
The most customary use of WebSocket is in real-time application development wherein it assists in a continual display of data at the client end. As the backend server sends back this data continuously, WebSocket allows uninterrupted pushing or transmitting this data in the already open connection. The use of WebSockets makes such data transmission quick and leverages the application's performance.
88-
2. A real-life example of such WebSocket utility is in the trading websites such as deriv. Here, WebSocket assist in data handling that is impelled by the deployed backend server to the client.
89-
3. ‍Creating a chat application
90-
Chat application developers call out WebSocket for help in operations like a one-time exchange and publishing/broadcasting the messages. As the same WebSocket connection is used for sending/receiving messages, communication becomes easy and quick.
86+
1. ‍When you're developing a real-time web application.
87+
The most customary use of WebSocket is in real-time application development wherein it assists in a continual display of data at the client end. As the back-end server sends back this data continuously, a WebSocket allows uninterrupted pushing or transmitting of this data in the already open connection. The use of WebSockets makes such data transmission quick and leverages the application's performance.
88+
2. For trading websites, such as Deriv.
89+
Here, WebSocket assist in data handling that is impelled by the deployed back-end server to the client.
90+
3. ‍When creating a chat application.
91+
Chat application developers call out WebSockets for help in operations like a one-time exchange and publishing/broadcasting messages. As the same WebSocket connection is used for sending/receiving messages, communication becomes easy and quick.
9192

92-
Now that it’s clear where WebSocket should be used, don’t forget to know the cases where it should be avoided and keep yourself away from tons of operational hassles.
93+
Now that we've established where WebSockets should be used, let's see where it is best to avoid them. This will help you steer clear of unnecessary operational hassles.
9394

9495
WebSocket shouldn’t be taken onboard when old data fetching is the need of the hour or need data only for one-time processing. In these cases, using HTTP protocols is a wise choice.
9596

0 commit comments

Comments
 (0)