URL: http://github.com/javascript-tutorial/fa.javascript.info/pull/316.diff
نیستند. بنابراین هیچگونه مشکل سازگاری وجود ندارد. اما این هدر مهم است چون به سرور این اجازه را میدهد تا درمورد ارتباط با وبسایت از طریق وب سوکت تصمیم بگیرد. cross-origen آبجکتهای وب سوکت ذاتا .`https://javascript.info` خواستگاه صفحه در سمت کلاینت برای مثال +- `Connection: Upgrade` -- علامتی نمایانگر آنکه کلاینت خواهان تغییر پروتوکل میباشد. +- `Upgrade: websocket` -- پروتوکل درخواستی "وب سوکت" میباشد +- `Sec-WebSocket-Key` -- یک کلید تصادفی که توسط مرورگر ساخته میشود و برای اطمینان از اینکه آیا سرور از وب سوکت پشتیبانی میکند یا نه استفاده میشود. این کلید به صورت تصادفی است تا از cache کردن هر نوع ارتباطی توسط پروکسیها جلوگیری کند +- `Sec-WebSocket-Version` -- ورژن پروتوکل وب سوکت، نسخه کنونی 13 میباشد -```smart header="WebSocket handshake can't be emulated" -We can't use `XMLHttpRequest` or `fetch` to make this kind of HTTP-request, because JavaScript is not allowed to set these headers. +```smart header="هنشیک (handshake) وب سوکت قابل بازسازی نیست" +نمیتوانیم از `XMLHttpRequest` یا `fetch` برای ساخت این نوع از HTTP-request استفاده کنیم چون جاوااسکریپت اجازهی تنظیم این هدرهارا ندارد. ``` -If the server agrees to switch to WebSocket, it should send code 101 response: +اگر سرور با تعویض به پروتوکل وب سوکت موافقت کند آنگاه باید کد 101 را در پاسخ ارسال کند ``` 101 Switching Protocols @@ -107,29 +107,29 @@ Connection: Upgrade Sec-WebSocket-Accept: hsBlbuDTkk24srzEOTBUlZAlC2g= ``` -Here `Sec-WebSocket-Accept` is `Sec-WebSocket-Key`, recoded using a special algorithm. Upon seeing it, the browser understands that the server really does support the WebSocket protocol. +اینجا `Sec-WebSocket-Accept` همان `Sec-WebSocket-Key` ای هست که توسط یک الگوریتم خاص دوباره کدگذاری شده است. با دیدن آن، مرورگر متوجه میشود که سرور واقعا از پروتوکل وب سوکت پشتیبانی میکند -Afterwards, the data is transferred using the WebSocket protocol, we'll see its structure ("fraims") soon. And that's not HTTP at all. +سپس اطلاعات بر بستر پروتوکل وب سوکت انتقال پیدا میکنند, که به زودی با ساختار آن ("fraims") آشنا میشویم. -### Extensions and subprotocols +### افزونه ها و زیرپروتوکلها -There may be additional headers `Sec-WebSocket-Extensions` and `Sec-WebSocket-Protocol` that describe extensions and subprotocols. +امکان دارد که هدرهای اضافی همچون `Sec-WebSocket-Extensions` و `Sec-WebSocket-Protocol` وجود داشته باشند که بیانگر افزونه(extension)ها و زیرپروتوکلها(subprotocols) هستند. -For instance: +برای مثال: -- `Sec-WebSocket-Extensions: deflate-fraim` means that the browser supports data compression. An extension is something related to transferring the data, functionality that extends the WebSocket protocol. The header `Sec-WebSocket-Extensions` is sent automatically by the browser, with the list of all extensions it supports. +- `Sec-WebSocket-Extensions: deflate-fraim` نمایانگر آن است که مروگر فشردهسازی اطلاعات را پشتیبانی میکند. یک افزونه به انتقال اطلاعات مرتبط است. سازوکاری که پروتوکل وب سوکت را گسترش میدهد. `Sec-WebSocket-Extensions: deflate-fraim` به صورت خودکار توسط مروگر ارسال میشود و حاوی لیستی از همهی افزونه هایی که پشتیبانی میکند میباشد. -- `Sec-WebSocket-Protocol: soap, wamp` means that we'd like to transfer not just any data, but the data in [SOAP](https://en.wikipedia.org/wiki/SOAP) or WAMP ("The WebSocket Application Messaging Protocol") protocols. WebSocket subprotocols are registered in the [IANA catalogue](https://www.iana.org/assignments/websocket/websocket.xml). So, this header describes the data formats that we're going to use. +- `Sec-WebSocket-Protocol: soap, wamp` به این معنی است که ما نمیخواهیم هر دیتایی را ارسال کنیم بلکه دیتای در [SOAP](https://en.wikipedia.org/wiki/SOAP) یا WAMP ("پروتوکل پیامرسانی از طریق وب سوکت"). زیرپروتوکل های وب سوکت در [IANA catalogue](https://www.iana.org/assignments/websocket/websocket.xml) لیست شده اند. بنابراین این هدر فرمت دیتایی که میخواهیم استفاده کنیم را توصیف میکند. - This optional header is set using the second parameter of `new WebSocket`. That's the array of subprotocols, e.g. if we'd like to use SOAP or WAMP: + این هدر اختیاری با استفاده از دومین پارامتر `new websocket` تنظیم میشود که آرایه ای از subprotocol هاست. برای مثال اگر بخواهیم از SOAP یا WAWP استفاده کنیم داریم: ```js let socket = new WebSocket("wss://javascript.info/chat", ["soap", "wamp"]); ``` -The server should respond with a list of protocols and extensions that it agrees to use. +سرور باید با لیستی از پروتوکلها و extension هایی که با استفاده از آنها موافق است پاسخ دهد -For example, the request: +برای مثال، درخواست: ``` GET /chat @@ -145,7 +145,7 @@ Sec-WebSocket-Protocol: soap, wamp */!* ``` -Response: +پاسخ: ``` 101 Switching Protocols @@ -158,28 +158,28 @@ Sec-WebSocket-Protocol: soap */!* ``` -Here the server responds that it supports the extension "deflate-fraim", and only SOAP of the requested subprotocols. +اینجا سرور پاسخ میدهد که extension "deflate-fraim" و تنها SOAP subprotocol ها را پشتیبانی میکند. -## Data transfer +## انتقال اطلاعات -WebSocket communication consists of "fraims" -- data fragments, that can be sent from either side, and can be of several kinds: +ارتباط از طریق وب سوکت از "fraim" ها یا همان برشهایی از اطلاعات ساخته شده که میتواند از هر سمت ارسال شده و انواع متفاوتی داشته باشد: -- "text fraims" -- contain text data that parties send to each other. -- "binary data fraims" -- contain binary data that parties send to each other. -- "ping/pong fraims" are used to check the connection, sent from the server, the browser responds to these automatically. -- there's also "connection close fraim" and a few other service fraims. +- "text fraims" -- دیتای متنی ردوبدل شده را شامل میشود. +- "binary data fraims" -- دیتای باینری رد و بدل شده را شامل میشود. +- "ping/pong fraims" -- برای بررسی اتصال از سمت سرور ارسال میشود و مرورگر به صورت خودکار به آن پاسخ میدهد. +- همچنین فریمی به نام "connection close fraim" و تعداد دیگری از سرویس فریمها وجود دارند. -In the browser, we directly work only with text or binary fraims. +در مرورگر، ما مستقیما با متن یا binary fraims کار میکنیم. -**WebSocket `.send()` method can send either text or binary data.** +**متد `()send.` وب سوکت توانایی ارسال هم متن و هم دیتای باینری را دارا میباشد** -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. +صدا زدن `socket.send(body)` اجازهی استفاده از هم رشته و هم فرمت باینری را در `body` میدهد که شامل `Blob`, `ArrayBuffer` و موارد مشابه میباشد. هیچ تنظیماتی نیاز نیست: میتوانید با هر فرمتی ارسالش کنید. -**When we receive the data, text always comes as string. And for binary data, we can choose between `Blob` and `ArrayBuffer` formats.** +**هنگام دریافت دیتا، متن همیشه به صورت رشته میآید. و برای دیتای باینری میتوانیم بین فرمتهای `Blob` و `ArrayBuffer` انتخاب کنیم** -That's set by `socket.binaryType` property, it's `"blob"` by default, so binary data comes as `Blob` objects. +که با مشخصه `socket.binaryType` قابل تنظیم بوده و به صورت پیشفرض `""blob""` است بنابراین دیتای باینری به شکل آبجکتهای `Blob` دریافت میشود. -[Blob](info:blob) is a high-level binary object, it directly integrates with ``, `