Skip to content

Commit 56da75f

Browse files
committed
update article.md -- websocket
1 parent d727238 commit 56da75f

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

5-network/11-websocket/article.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ Sec-WebSocket-Protocol: soap
165165

166166
ارتباط از طریق وب سوکت از "frame" ها یا همان برش‌هایی از اطلاعات ساخته شده که میتواند از هر سمت ارسال شده و انواع متفاوتی داشته باشد:
167167

168-
- "text frames" -- contain text data that parties send to each other.
169-
- "binary data frames" -- contain binary data that parties send to each other.
170-
- "ping/pong frames" are used to check the connection, sent from the server, the browser responds to these automatically.
171-
- there's also "connection close frame" and a few other service frames.
168+
- "text frames" -- دیتای متنی ردوبدل شده را شامل می‌شود.
169+
- "binary data frames" -- دیتای باینری رد و بدل شده را شامل می‌شود.
170+
- "ping/pong frames" -- برای بررسی اتصال از سمت سرور ارسال می‌شود و مرورگر به صورت خودکار به آن پاسخ می‌دهد.
171+
- همچنین فریمی به نام "connection close frame" و تعداد دیگری از سرویس فریم‌ها وجود دارند.
172172

173-
In the browser, we directly work only with text or binary frames.
173+
در مرورگر، ما مستقیما با متن یا binary frames کار میکنیم.
174174

175-
**WebSocket `.send()` method can send either text or binary data.**
175+
**متد `()send.` وب سوکت توانایی ارسال هم متن و هم دیتای باینری را دارا میباشد**
176176

177-
A call `socket.send(body)` allows `body` in string or a binary format, including `Blob`, `ArrayBuffer`, etc. No settings are required: just send it out in any format.
177+
صدا زدن `socket.send(body)` اجازه‌ی استفاده از هم رشته و هم فرمت باینری را در `body` می‌دهد که شامل `Blob`, `ArrayBuffer` و موارد مشابه میباشد. هیچ تنظیماتی نیاز نیست: میتوانید با هر فرمتی ارسالش کنید.
178178

179-
**When we receive the data, text always comes as string. And for binary data, we can choose between `Blob` and `ArrayBuffer` formats.**
179+
**هنگام دریافت دیتا، متن همیشه به صورت رشته می‌آید. و برای دیتای باینری میتوانیم بین فرمت‌های `Blob` و `ArrayBuffer` انتخاب کنیم**
180180

181-
That's set by `socket.binaryType` property, it's `"blob"` by default, so binary data comes as `Blob` objects.
181+
که با مشخصه `socket.binaryType` قابل تنظیم بوده و به صورت پیشفرض `""blob""` است بنابراین دیتای باینری به شکل آبجکت‌های `Blob` دریافت می‌شود.
182182

183183
[Blob](info:blob) is a high-level binary object, it directly integrates with `<a>`, `<img>` and other tags, so that's a sane default. But for binary processing, to access individual data bytes, we can change it to `"arraybuffer"`:
184184

@@ -189,72 +189,72 @@ socket.onmessage = (event) => {
189189
};
190190
```
191191

192-
## Rate limiting
192+
## محدود کردن نرخ
193193

194-
Imagine, our app is generating a lot of data to send. But the user has a slow network connection, maybe on a mobile internet, outside of a city.
194+
تصور کنید که برنامه‌ی ما مقدار زیادی دیتا ارسال میکند اما اینترنت کاربر سرعت پایینی دارد شاید بشه اینترنت همراه خارج از شهر رو مثال زد.
195195

196-
We can call `socket.send(data)` again and again. But the data will be buffered (stored) in memory and sent out only as fast as network speed allows.
196+
ما `socket.send(data)` را بارها و بارها صدا میزنیم. اما دیتا در حافظه بافر (ذخیره) شده و زمانی که سرعت شبکه به حد کافی برسد به بیرون ارسال خواهد شد.
197197

198-
The `socket.bufferedAmount` property stores how many bytes remain buffered at this moment, waiting to be sent over the network.
198+
مشخصه `socket.bufferedAmount` تعداد بایت‌های ذخیره شده درلحظه و درحال انتظار برای ارسال تحت شبکه را ذخیره می‌کند.
199199

200-
We can examine it to see whether the socket is actually available for transmission.
200+
با ارزیابی این پارامتر میتونیم بفهمیم که آیا سوکت واقعا برای انتقال دردسترس است یا نه
201201

202202
```js
203-
// every 100ms examine the socket and send more data
204-
// only if all the existing data was sent out
203+
// هر صد میلی ثانیه سوکت را بررسی کرده و دیتای بیشتری را ارسال میکند
204+
// تنها زمانی که همه‌ی دیتای موجود ارسال شده باشد
205205
setInterval(() => {
206206
if (socket.bufferedAmount == 0) {
207207
socket.send(moreData());
208208
}
209209
}, 100);
210210
```
211211

212+
## بستن اتصال
212213

213-
## Connection close
214+
به طور معمولی زمانی که یک طرف قصد بستن اتصال را داشته باشد(هر دوی مروگر و سرور حق برابری برای اینکار دارا هستند.), آنها عبارت `connection close frame` را به همراه یک کد عددی و دلیل اینکار را به شکل متنی ارسال میکنند.
214215

215-
Normally, when a party wants to close the connection (both browser and server have equal rights), they send a "connection close frame" with a numeric code and a textual reason.
216+
روش انجام این کار به شکل زیر است:
216217

217-
The method for that is:
218218
```js
219219
socket.close([code], [reason]);
220220
```
221221

222-
- `code` is a special WebSocket closing code (optional)
223-
- `reason` is a string that describes the reason of closing (optional)
222+
- `code` یک کد خاص برای بستن وب سوکت (اختیاری)
223+
- `reason` رشته‌ای که علت بستن اتصال را توضیح می‌دهد (اختیاری)
224224

225-
Then the other party in the `close` event handler gets the code and the reason, e.g.:
225+
سپس طرف دیگر رویداد کد `close` و علت آنرا دریافت میکند. برای مثال:
226226

227227
```js
228-
// closing party:
228+
// سمتی که ارتباط را میبندد:
229229
socket.close(1000, "Work complete");
230230

231-
// the other party
232-
socket.onclose = event => {
231+
// سمت دیگر:
232+
socket.onclose = (event) => {
233233
// event.code === 1000
234234
// event.reason === "Work complete"
235235
// event.wasClean === true (clean close)
236236
};
237237
```
238238

239-
Most common code values:
239+
رایجع‌ترین کدها و مقادیر آنها:
240240

241-
- `1000` -- the default, normal closure (used if no `code` supplied),
242-
- `1006` -- no way to set such code manually, indicates that the connection was lost (no close frame).
241+
- `1000` -- بستن پیش‌فرض و عادی (زمانی که `code` نباشد استفاده می‌شود),
242+
- `1006` -- راهی برای تنظیم این کد به صورت دستی وجود نداشته و نمایانگر از دست رفتن ارتباط هست (no close frame)
243243

244-
There are other codes like:
244+
کدهای دیگر مثل موارد زیر هم وجود دارند:
245245

246246
- `1001` -- the party is going away, e.g. server is shutting down, or a browser leaves the page,
247-
- `1009` -- the message is too big to process,
248-
- `1011` -- unexpected error on server,
249-
- ...and so on.
247+
- `1009` -- حجم پیام برای انجام پردازش زیاد است,
248+
- `1011` -- خطای پیش‌بینی نشده در سرور,
249+
- ...و غیره.
250250

251-
The full list can be found in [RFC6455, §7.4.1](https://tools.ietf.org/html/rfc6455#section-7.4.1).
251+
لیست کامل رو میتونید در [RFC6455, §7.4.1](https://tools.ietf.org/html/rfc6455#section-7.4.1) پیدا کنید.
252252

253-
WebSocket codes are somewhat like HTTP codes, but different. In particular, codes lower than `1000` are reserved, there'll be an error if we try to set such a code.
253+
کدهای وب سوکت تاحدی مشابه کدهای HTTP میباشند اما متفاوتند. به صورت خاص کدهای کمتر از `1000` از قبل رزرو شده اند و اگر تلاش کنیم تا یکی از این کدهارو استفاده کنیم به ارور برخورد خواهیم کرد.
254254

255255
```js
256-
// in case connection is broken
257-
socket.onclose = event => {
256+
// اگر ارتباط دچار مشکل باشد:
257+
socket.onclose = (event) => {
258258
// event.code === 1006
259259
// event.reason === ""
260260
// event.wasClean === false (no closing frame)

0 commit comments

Comments
 (0)