|
1 | | -# WebSocket |
| 1 | +# وب سوکت |
2 | 2 |
|
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" رد و بدل شوند. |
4 | 4 |
|
5 | | -WebSocket is especially great for services that require continuous data exchange, e.g. online games, real-time trading systems and so on. |
| 5 | +به طور خاص وب سوکت برای سرویسهایی که نیاز به تبادل اطلاعات به شکل مستمر دارند مثل بازیهای آنلاین، سیستمهای ترید لحظهای و امثالهم استفاده میشود. |
6 | 6 |
|
7 | | -## A simple example |
| 7 | +## یک مثال ساده |
8 | 8 |
|
9 | | -To open a websocket connection, we need to create `new WebSocket` using the special protocol `ws` in the url: |
| 9 | +برای باز کردن یک ارتباط از نوع وب سوکت، ما نیاز به ایجاد یک `وب سوکت جدید` با استفاده از پروتوکل مخصوص `ws` در url داریم: |
10 | 10 |
|
11 | 11 | ```js |
12 | 12 | let socket = new WebSocket("*!*ws*/!*://javascript.info"); |
13 | 13 | ``` |
14 | 14 |
|
15 | | -There's also encrypted `wss://` protocol. It's like HTTPS for websockets. |
| 15 | +همچنین پروتوکل رمزگذاری شده `wss://` وجود دارد. این پروتوکل همانند پروتوکل HTTPS برای وب سوکت ها میباشد. |
16 | 16 |
|
17 | 17 | ```smart header="Always prefer `wss://`" |
18 | | -The `wss://` protocol is not only encrypted, but also more reliable. |
| 18 | +پروتوکل `wss://` نه تنها رمزگذاری شده بلکه قابل اعتماد نیز هست |
19 | 19 |
|
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://` باعث قابل رویت بودن اطلاعات توسط هر رابطی میشود. چون پروکسی سرورهای قدیمی راجع به وب سوکت ها اطلاعی ندارند ممکن است هدرها را "ناآشنا" تشخیص داده و ارتبط را قطع کنند. |
21 | 21 |
|
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 | +```` |
24 | 25 |
|
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`** -- بسته شدن ارتباط . |
30 | 31 |
|
31 | 32 | ...And if we'd like to send something, then `socket.send(data)` will do that. |
32 | 33 |
|
|
0 commit comments