Skip to content

Commit e7b3ae8

Browse files
committed
Update article.md -- websocket
1 parent 875b121 commit e7b3ae8

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

5-network/11-websocket/article.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
# WebSocket
1+
# وب سوکت
22

3-
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.
3+
پروتوکل _وب‌ سوکت_, همانطور که در [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455) توضیحات آن ارائه شده است, راهی را برای ردوبدل کردن دیتا بین مرورگر و سرور به شکل یک ارتباط مستمر میسر میسازد. در این پروتوکل اطلاعات میتواندد بدون شکستن ارتباط و نیاز به درخواست HTTP اضافه به شکل دوسویه و در قالب "packets" رد و بدل شوند.
44

5-
WebSocket is especially great for services that require continuous data exchange, e.g. online games, real-time trading systems and so on.
5+
به طور خاص وب سوکت برای سرویس‌هایی که نیاز به تبادل اطلاعات به شکل مستمر دارند مثل بازیهای آنلاین، سیستم‌های ترید لحظه‌ای و امثالهم استفاده می‌شود.
66

7-
## A simple example
7+
## یک مثال ساده
88

9-
To open a websocket connection, we need to create `new WebSocket` using the special protocol `ws` in the url:
9+
برای باز کردن یک ارتباط از نوع وب سوکت، ما نیاز به ایجاد یک `وب سوکت جدید` با استفاده از پروتوکل مخصوص `ws` در url داریم:
1010

1111
```js
1212
let socket = new WebSocket("*!*ws*/!*://javascript.info");
1313
```
1414

15-
There's also encrypted `wss://` protocol. It's like HTTPS for websockets.
15+
همچنین پروتوکل رمزگذاری شده `wss://` وجود دارد. این پروتوکل همانند پروتوکل HTTPS برای وب سوکت ها میباشد.
1616

1717
```smart header="Always prefer `wss://`"
18-
The `wss://` protocol is not only encrypted, but also more reliable.
18+
پروتوکل `wss://` نه تنها رمزگذاری شده بلکه قابل اعتماد نیز هست
1919

20-
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.
20+
عدم رمزگذاری در ارتباط با پروتوکل `ws://` باعث قابل رویت بودن اطلاعات توسط هر رابطی میشود. چون پروکسی سرورهای قدیمی راجع به وب سوکت ها اطلاعی ندارند ممکن است هدرها را "ناآشنا" تشخیص داده و ارتبط را قطع کنند.
2121

22-
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.
23-
```
22+
از طرف دیگر، پروتوکل `wss://` برروی TLS بوده (همانطور که HTTPS همان HTTP برروی TLS میباشد.) لایه امنیت انتقال اطلاعات را از سمت فرستنده رمزگذاری کرده و در سمت گیرنده رمزگذاری میکند. بنابراین اطلاعات به شکل رمزگذاری شده از میان پروکسی‌ها عبور میکنند. آنها نمیتوانند ببینند چه چیزی درون این بسته ها وجود دارد و تنها آنهارا عبور میدهند.
23+
24+
````
2425
25-
Once the socket is created, we should listen to events on it. There are totally 4 events:
26-
- **`open`** -- connection established,
27-
- **`message`** -- data received,
28-
- **`error`** -- websocket error,
29-
- **`close`** -- connection closed.
26+
زمانی که سوکت ایجاد میشود، ما باید به رویدادهای آن گوش کنیم. درمجموع 4 نوع رویداد وجود دارد:
27+
- **`open`** -- ارتبط ساخته شده است,
28+
- **`message`** -- دریافت اطلاعات,
29+
- **`error`** -- خطای وب سوکت,
30+
- **`close`** -- بسته شدن ارتباط .
3031
3132
...And if we'd like to send something, then `socket.send(data)` will do that.
3233

0 commit comments

Comments
 (0)