{"id":455160,"date":"2025-04-08T15:00:43","date_gmt":"2025-04-08T15:00:43","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=455160"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=455160","title":{"rendered":"<span>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Kotlin + Ktor: \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Ktor<\/strong> \u2013 \u044d\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u044b \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <strong>\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c Kotlin<\/strong> Ktor \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e WebSocket-\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (<a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/09\/ktor-101-efficient-jvm-http-toolkit\/#:~:text=Thanks%20to%20coroutines%2C%20Ktor%20makes,simple%20echo%20server%20with%20WebSockets\" rel=\"noopener noreferrer nofollow\">Ktor 101: Efficient JVM HTTP Toolkit | The IntelliJ IDEA Blog<\/a>). \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0435\u0441\u0441\u0438\u0439, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043a\u043e\u043c\u043d\u0430\u0442 (\u0447\u0430\u0442\u043e\u0432, \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043b\u043e\u0431\u0431\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u043d\u0433\u0430), \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (heartbeat, \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u044b), \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u0438\u0437 \u0431\u043e\u0435\u0432\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430.<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Ktor<\/h3>\n<p>\u041f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432\u0430\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0438 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0441\u0435\u0442\u0438 (WebSocket-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b)<\/strong>: \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0412 Ktor \u044d\u0442\u043e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b <code>webSocket(...)<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>routing { ... }<\/code>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443-\u0441\u0435\u0441\u0441\u0438\u044e. \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0435\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435\/\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 (\u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b)<\/strong>: \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u043c, \u0433\u0435\u0439\u043c\u043f\u043b\u0435\u0439 \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u043a\u043e\u043c\u043d\u0430\u0442, \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\/\u0441\u0435\u0441\u0441\u0438\u0439 \u0438 \u0434\u0440. \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 WebSocket-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u2013 \u043e\u043d\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0439<\/strong>: \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u044d\u0448\u0435\u043c, \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 API \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u043c\u0438. \u042d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u0442.\u0434. \u041e\u043d \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442 WebSocket-\u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u2013 \u0432\u0435\u0440\u0445\u043d\u0438\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0411\u0414, Redis, Kafka \u0438 \u043f\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u044c: \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439) \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043c\u043d\u0430\u0442, \u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u043e\u0434 \u0441\u0435\u0441\u0441\u0438\u0439.<\/p>\n<h4>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/h4>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0443 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u044d\u0442\u0430\u043f\u044b:<\/p>\n<ol>\n<li>\n<p><strong>Handshake \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> \u2013 Ktor \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u0440\u0435\u0434\u0435\u043d\u0448\u0430\u043b\u044b. Ktor \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 Authorization \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u044f WebSocket, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u2013 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 URL \u0438\u043b\u0438 cookie \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438. \u041f\u0440\u0438 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0435 \u2013 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438<\/strong> \u2013 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, userId, \u0438\u043c\u044f) \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b (\u0435\u0433\u043e WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043a\u0430\u043d\u0430\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435). \u0421\u0435\u0441\u0441\u0438\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u043c \u0440\u0435\u0435\u0441\u0442\u0440\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435<\/strong> \u2013 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u044b (\u0447\u0430\u0442-\u043a\u043e\u043c\u043d\u0430\u0442\u0430, \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043c\u0430\u0442\u0447), \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 URL (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>ws:\/\/server\/game?roomId=X<\/code>) \u0438\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043a\u043e\u043c\u043d\u0430\u0442 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438<\/strong> \u2013 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b: \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439). \u042d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <strong>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438<\/strong>. Ktor \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <strong>\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b<\/strong> \u0438 <strong>\u043a\u0430\u043d\u0430\u043b\u044b<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/strong> \u2013 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u044b\u0432\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u043c) \u0441\u0435\u0440\u0432\u0435\u0440 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u0438\u0437 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445, \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u2013 \u0447\u0442\u043e\u0431\u044b \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043e\u043f\u043e\u0432\u0435\u0441\u0442\u0438\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445) \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0415\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u0440\u043e \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442).<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 Ktor \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442-\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439, \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 <strong>\u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0435\u0441\u0441\u0438\u0438<\/strong> \u0442\u0438\u043f\u0430 <code>DefaultWebSocketServerSession<\/code> (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=Inside%20the%20,are%20available%20within%20the%20block\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). \u042d\u0442\u0430 \u0441\u0435\u0441\u0441\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u043a\u0430\u043d\u0430\u043b\u0430: <code>incoming<\/code> \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432 \u0438 <code>outgoing<\/code> \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445. \u0412 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>for(frame in incoming) { ... }<\/code> \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 <code>send(...)<\/code> \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0430 \u043d\u0430 Ktor:<\/p>\n<pre><code class=\"kotlin\">routing {     webSocket(\"\/ws\") {         \/\/ \u041f\u0440\u0438\u043c\u0435\u0440: \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         send(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0435 \u0438\u043c\u044f:\")         for (frame in incoming) {             frame as? Frame.Text ?: continue             val text = frame.readText()             if (text.equals(\"bye\", ignoreCase=true)) {                 close(CloseReason(CloseReason.Codes.NORMAL, \"Client said BYE\"))             } else {                 send(\"\u042d\u0445\u043e: \u0412\u044b \u043f\u0440\u0438\u0441\u043b\u0430\u043b\u0438 \\\"$text\\\"\")             }         }     } } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 (\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f echo-\u0441\u0435\u0440\u0432\u0435\u0440\u0430) \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 <code>incoming<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>send<\/code> \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u0440\u0430\u0437\u0431\u043e\u0440 JSON-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0432\u044b\u0437\u043e\u0432\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u043c \u0438 \u0442.\u043f.<\/p>\n<h3>Kotlin Coroutines \u0438 Channels \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439<\/h3>\n<p><strong>\u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b Kotlin<\/strong> \u2013 \u0441\u0435\u0440\u0434\u0446\u0435\u0432\u0438\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 Ktor. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u00ab1 \u043f\u043e\u0442\u043e\u043a \u043d\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u00bb, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0442\u044b\u0441\u044f\u0447 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u043c \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u041a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0411\u0414, \u043f\u043e\u0442\u043e\u043a \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442 \u2013 \u043e\u043d \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 <strong>\u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430<\/strong> \u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0434\u0430\u0436\u0435 \u043d\u0430 4-8 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u043e\u0432.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <strong>\u043a\u0430\u043d\u0430\u043b\u044b<\/strong> (Channels) \u2013 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u044b \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u0440\u0438\u0451\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/strong>: \u0425\u043e\u0442\u044f \u043c\u043e\u0436\u043d\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d-\u0446\u0438\u043a\u043b\u0435 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c, \u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0430\u0441\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0438 \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>\u043a\u0430\u043d\u0430\u043b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041e\u0434\u0438\u043d \u0444\u043e\u043d\u043e\u0432\u044b\u0439 coroutine \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 coroutine \u2013 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u043a\u0430\u043d\u0430\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <code>session.send<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435\u0436\u0451\u0441\u0442\u043a\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u2013 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043a\u0430\u043d\u0430\u043b \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u043e\u0434\u0438\u043d coroutine \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0438\u0445, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0433\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>Broadcaster (Actor)<\/strong>: \u0414\u0440\u0443\u0433\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u2013 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0430\u043a\u0442\u043e\u0440<\/strong> (actor) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0410\u043a\u0442\u043e\u0440 \u2013 \u044d\u0442\u043e coroutine \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u043c, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439) \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f: \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u0445, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 (\u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0441\u044f\/\u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f) \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u043e\u0440 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 coroutine \u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 <code>Channel&lt;RoomEvent&gt;<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>\u043a\u0430\u043d\u0430\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u0438<\/strong>:<\/p>\n<pre><code class=\"kotlin\">class ClientSession(val session: DefaultWebSocketServerSession) {     val outgoing: Channel&lt;String&gt; = Channel(capacity = 16)  \/\/ \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439      init {         \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c coroutine-\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c         GlobalScope.launch {             for (msg in outgoing) {                 session.send(msg)  \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 JSON             }         }     } } <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>ClientSession(session)<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>ConcurrentHashMap<\/code> \u043f\u043e ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0445\u043e\u0447\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 <code>clientSession.outgoing.trySend(message)<\/code> (\u0438\u043b\u0438 <code>launch { clientSession.outgoing.send(message) }<\/code> \u0434\u043b\u044f suspend-\u0432\u044b\u0437\u043e\u0432\u0430). \u0422\u0430\u043a\u043e\u0435 decoupling \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u043d\u0430\u043b (\u0434\u0430\u0436\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430\/\u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430), \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e \u0441\u0435\u0442\u0438. \u041a\u043e\u0440\u0443\u0442\u0438\u043d-\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438<\/strong> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443\u0437\u043a\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u2013 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e \u0441\u0435\u0442\u0438 \u2013 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u044e. \u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 (\u043d\u0438\u0437\u043a\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0438\u043b\u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u2013 \u0435\u0433\u043e \u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u0438 \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0451\u043c\u043a\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0438\u043b\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439. \u042d\u0442\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443: \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445, \u0442.\u043a. \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e.<\/p>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u043a\u0430\u043d\u0430\u043b\u0430\u043c \u043c\u043e\u0433 \u0431\u044b \u0431\u044b\u0442\u044c <code>SharedFlow<\/code>\/<code>StateFlow<\/code> \u0438\u0437 kotlinx.coroutines. \u0412 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Ktor \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>MutableSharedFlow<\/strong> \u0434\u043b\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0432\u0435\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044f\u043c (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=Example%3A%20Handle%20multiple%20sessions\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>) (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,job.cancel%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). SharedFlow \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u00ab\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435\u0439, \u043e\u0434\u0438\u043d \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u00bb \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0431\u043e\u0440\u0449\u0438\u043a (<code>sharedFlow.collect<\/code>) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c WebSocket-\u0441\u0435\u0441\u0441\u0438\u0438, \u0438 \u043f\u0440\u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u043d\u043e <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u043c<\/strong> \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0441\u0435\u0441\u0441\u0438\u0439 (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,job.cancel%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). \u042d\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u0437\u0430\u0431\u043e\u0442 \u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e SharedFlow \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043c\u043d\u0430\u0442 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 (\u0442.\u043a. \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u044b), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c\u0441\u044f. \u0412\u044b\u0431\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 Channel \u0438 Flow \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u043a\u0443\u0441\u0430 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438; \u0434\u043b\u044f middle-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043e\u0431\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<h3>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043e\u043c\u043d\u0430\u0442<\/h3>\n<p><strong>\u041a\u043e\u043c\u043d\u0430\u0442\u044b<\/strong> \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0447\u0430\u0442\u043e\u0432, \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u0435\u0440\u043d\u044b\u0445 \u0438\u0433\u0440, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438 \u0442.\u0434. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e, \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u2013 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439: \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438\u0434\u0443\u0442 \u0432\u0441\u0435\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430\u043c \u0435\u0433\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u044b (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e), \u043b\u0438\u0431\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0430\u0442\u0443.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041e\u0434\u0438\u043d \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><strong>\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043a\u043e\u043c\u043d\u0430\u0442 (RoomManager)<\/strong>: \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 singleton \u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043d\u0430\u0442. \u0423 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f. \u0427\u0430\u0441\u0442\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 <code>Map&lt;RoomId, Room&gt;<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u044b (Room)<\/strong>: \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0441\u043f\u0438\u0441\u043e\u043a (\u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440) \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0447\u0430\u0442\u0430, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0433\u0440\u044b). \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0432\u0438\u0434\u0435 \u0443 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p><code>join(session: ClientSession)<\/code> \u2013 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p><code>leave(session: ClientSession)<\/code> \u2013 \u0443\u0431\u0440\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p><code>broadcast(message: Message)<\/code> \u2013 \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u043d\u0430\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0430\u043c\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 <strong>\u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438<\/strong> \u0438\u043b\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0441\u0441\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\">class Room(val id: String) {     private val participants: MutableSet&lt;ClientSession&gt; = mutableSetOf()      fun join(client: ClientSession) {         participants += client         broadcast(\"${client.sessionId} \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0441\u044f \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435\")     }      fun leave(client: ClientSession) {         participants -= client         broadcast(\"${client.sessionId} \u043f\u043e\u043a\u0438\u043d\u0443\u043b \u043a\u043e\u043c\u043d\u0430\u0442\u0443\")     }      fun broadcast(text: String) {         for (client in participants) {             client.outgoing.trySend(text)         }     } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>ClientSession.outgoing<\/code> \u2013 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 Channel, \u043a\u0443\u0434\u0430 \u043c\u044b \u043a\u043b\u0430\u0434\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0422\u0430\u043a\u043e\u0439 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443 \u0440\u0430\u0437\u043e\u0448\u043b\u0451\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432\u0441\u0435\u043c \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Message (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 <code>sender<\/code>, <code>payload<\/code>, <code>timestamp<\/code>), \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 JSON.<\/p>\n<p><strong>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u043a\u043e\u043c\u043d\u0430\u0442\u044b<\/strong>: \u041a\u043e\u0433\u0434\u0430 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0432 \u043a\u0430\u043a\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 URL, \u043f\u043e\u043b\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 matchmaking. \u041f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f roomId \u2013 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>RoomManager.join(roomId, session)<\/code>. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c ID \u043d\u0435\u0442, \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f. \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043b\u0438\u043c\u0438\u0442\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 100 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432) \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (\u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043b\u043e\u0431\u0431\u0438).<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>\u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, realtime \u0438\u0433\u0440\u0430), \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <strong>\u0446\u0438\u043a\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f<\/strong> \u043a\u043e\u043c\u043d\u0430\u0442\u044b (game loop), \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b 10-30 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043c\u043e\u0433\u0443\u0442 \u0438\u0434\u0442\u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0435\u0433\u043e \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430) \u0438 \u043e\u0431\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b).<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u2013 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0438 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <em>actor<\/em>-\u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043c\u043d\u0430\u0442\u0443: \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u043a\u0430\u043a \u0430\u043a\u0442\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2013 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u0438\u0433\u0440\u043e\u043a\u043e\u0432 (\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f) \u0438 \u0442\u0438\u043a \u0442\u0430\u0439\u043c\u0435\u0440\u0430 (\u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f). \u042d\u0442\u043e \u0443\u0431\u0435\u0440\u0435\u0436\u0451\u0442 \u043e\u0442 \u0433\u043e\u043d\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 \u0438\u0433\u0440\u043e\u043a\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u2013 \u0430\u043a\u0442\u043e\u0440 \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b, \u0433\u0434\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Runnable<\/code> \u0438 <code>Updatable<\/code> \u2013 \u0443 \u043d\u0435\u0451 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b <code>onRoomCreated<\/code>, <code>onBattleStarted<\/code>, <code>onDisconnect<\/code> \u0438 \u0442.\u0434., \u0430 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0432 \u043d\u0435\u043a\u043e\u043c <code>WebSocketMessagePublisher<\/code> (<a href=\"https:\/\/habr.com\/ru\/articles\/800689\/#:~:text=%D0%9E%D1%81%D0%BD%D0%BE%D0%B2%D1%83%20%D0%B8%D0%B3%D1%80%D0%BE%D0%B2%D0%BE%D0%B9%20%D0%BB%D0%BE%D0%B3%D0%B8%D0%BA%D0%B8%20%D0%BF%D1%80%D0%B5%D0%B4%D1%81%D1%82%D0%B0%D0%B2%D0%BB%D1%8F%D0%B5%D1%82%20%D0%B8%D0%B3%D1%80%D0%BE%D0%B2%D0%B0%D1%8F,%D0%BA%D0%BE%D0%BC%D0%BD%D0%B0%D1%82%D0%B0%C2%A0%E2%80%94%20GameRoom\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Kotlin, Webflux \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BattleRoyale\/Matchmaking \/ \u0425\u0430\u0431\u0440<\/a>) (<a href=\"https:\/\/habr.com\/ru\/articles\/800689\/#:~:text=override%20fun%20onDisconnect,send%28userSession%2C%20message\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Kotlin, Webflux \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BattleRoyale\/Matchmaking \/ \u0425\u0430\u0431\u0440<\/a>). \u041f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0438\u0433\u0440\u043e\u043a\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430\u043c (\u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0443) (<a href=\"https:\/\/habr.com\/ru\/articles\/800689\/#:~:text=override%20fun%20onRoomCreated%28userSessions%3A%20List,%7D\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Kotlin, Webflux \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BattleRoyale\/Matchmaking \/ \u0425\u0430\u0431\u0440<\/a>) (<a href=\"https:\/\/habr.com\/ru\/articles\/800689\/#:~:text=override%20fun%20onDestroy%28userSessions%3A%20List,%7D\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Kotlin, Webflux \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BattleRoyale\/Matchmaking \/ \u0425\u0430\u0431\u0440<\/a>). \u0422\u0430\u043a\u043e\u0439 \u0434\u0438\u0437\u0430\u0439\u043d \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0433\u0440\u044b \u043e\u0442 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430: \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u201c\u043e\u0442\u043f\u0440\u0430\u0432\u044c \u0432\u0441\u0435\u043c \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u201d, \u0430 \u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438 (\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0432\u044b\u0431\u043e\u0440 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f) \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440: \u0447\u0430\u0442-\u043a\u043e\u043c\u043d\u0430\u0442\u0430<\/strong> \u2013 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u044b. \u0412\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043b\u044e\u0431\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c. \u0422\u0443\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0435\u0441\u0441\u0438\u0439. \u041d\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (\u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438) \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>room.broadcast(message)<\/code>.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043b<\/strong> \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 WebRTC-\u0441\u0438\u0433\u043d\u0430\u043b\u0438\u043d\u0433\u0435 \u0434\u043b\u044f \u0432\u0438\u0434\u0435\u043e\u0437\u0432\u043e\u043d\u043a\u043e\u0432, \u0433\u0434\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f SDP-\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438\/\u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0435\u0440. \u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043c\u0430\u043b\u043e (2-5), \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0430\u0434\u0440\u0435\u0441\u043d\u044b\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u043c, \u0430 \u0438\u043c\u0435\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0443: <code>sendTo(recipientId, message)<\/code>. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 <code>ClientSession<\/code> \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u0435\u0433\u043e \u043a\u0430\u043d\u0430\u043b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p><strong>\u0418\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u043a\u043e\u043c\u043d\u0430\u0442<\/strong>: \u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u0435\u0440\u0436\u0430\u0442\u044c <strong>\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u043d\u0430\u0442<\/strong> \u2013 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043c\u0435\u0448\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443. \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u2013 \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u0445 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0442\u0430\u0445), \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u0432\u0441\u0435\u0445, \u0430 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443\/\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u042d\u0442\u0438 \u043a\u0435\u0439\u0441\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c: \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043c\u0430\u043f\u0443 <code>userId -&gt; sessions\/rooms<\/code>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0438\u0445 \u0432\u0441\u0435 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435).<\/p>\n<h3>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432: heartbeat \u0438 \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430<\/h3>\n<p><strong>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/strong> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d), \u0435\u0433\u043e \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443(\u044b), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0442, \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438). \u0413\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>Heartbeat (\u043f\u0438\u043d\u0433\/\u043f\u043e\u043d\u0433)<\/h4>\n<p>WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0435, \u0438 \u0441\u0435\u0442\u044c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0434\u0451\u0436\u043d\u0430. \u041a\u043b\u0438\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043f\u0440\u043e\u043f\u0430\u0441\u0442\u044c (\u043f\u043e\u0442\u0435\u0440\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c), \u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0443\u0437\u043d\u0430\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e (TCP \u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c &#171;\u043c\u0435\u0440\u0442\u0432\u043e\u0435&#187; \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u0438\u043d\u0443\u0442\u0430\u043c\u0438). <strong>Heartbeat<\/strong> \u2013 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0432\u044f\u0437\u0438. \u0412 WebSocket-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u044b <code>ping\/pong<\/code> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. Ktor \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0438\u043d\u0433 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 WebSockets:<\/p>\n<pre><code class=\"kotlin\">install(WebSockets) {     pingPeriod = Duration.ofSeconds(15)     timeout = Duration.ofSeconds(30)     masking = false     maxFrameSize = Long.MAX_VALUE } <\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0437 \u0432 15 \u0441\u0435\u043a\u0443\u043d\u0434 \u0448\u043b\u0451\u0442 <code>Ping<\/code> \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043e\u0436\u0438\u0434\u0430\u044f \u043e\u0442 \u043d\u0435\u0433\u043e <code>Pong<\/code> \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 30 \u0441\u0435\u043a. \u0415\u0441\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d, Ktor \u0437\u0430\u043a\u0440\u043e\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 (\u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u0432\u0430\u043b\u0438\u043b\u0441\u044f) (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=install%28WebSockets%29%20,MAX_VALUE%20masking%20%3D%20false\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). <strong>Ping\/Pong<\/strong> \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438\/NAT, \u0438 \u0441\u0432\u043e\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u044b\u0432\u044b (<a href=\"https:\/\/ably.com\/blog\/scaling-pub-sub-with-websockets-and-redis#:~:text=WebSocket%20connections%20are%20persistent%2C%20so,ordering%20guarantees%20of%20WebSocket%20streams\" rel=\"noopener noreferrer nofollow\">Scaling Pub\/Sub with WebSockets and Redis<\/a>).<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044c\u043d\u043e\u0433\u043e ping, \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 <strong>\u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 heartbeat<\/strong>: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0435 N \u0441\u0435\u043a\u0443\u043d\u0434 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>\"ping\"<\/code> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 <code>\"pong\"<\/code>. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438, \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <code>pong<\/code> \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435). \u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 WebSocket \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u2013 \u0447\u0430\u0449\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>pingPeriod<\/code>.<\/p>\n<p>\u041f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 heartbeat \u0432\u0430\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b. \u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u044b\u0435 \u043f\u0438\u043d\u0433\u0438 \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 \u0441\u0435\u0442\u044c (\u0438 \u0431\u0430\u0442\u0430\u0440\u0435\u044e \u043d\u0430 \u043c\u043e\u0431. \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445), \u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0440\u0435\u0434\u043a\u0438\u0435 \u2013 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u044e\u0442 &#171;\u043f\u0440\u0438\u0437\u0440\u0430\u0447\u043d\u044b\u0435&#187; \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (<a href=\"https:\/\/ably.com\/blog\/scaling-pub-sub-with-websockets-and-redis#:~:text=WebSocket%20connections%20are%20persistent%2C%20so,ordering%20guarantees%20of%20WebSocket%20streams\" rel=\"noopener noreferrer nofollow\">Scaling Pub\/Sub with WebSockets and Redis<\/a>). \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e 15-30 \u0441\u0435\u043a\u0443\u043d\u0434 \u2013 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043f\u0438\u043d\u0433\u0430, \u0430 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0432 ~2 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0436\u0435 \u043f\u0438\u043d\u0433\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430: \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435\u043e\u0442\u0432\u0435\u0442\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u0443 \u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u0430\u043a \u043f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u043c disconnect (cleanup \u0441\u0435\u0441\u0441\u0438\u0438, \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b). \u0412 Ktor, \u0435\u0441\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d <code>timeout<\/code>, \u0440\u0430\u0437\u0440\u044b\u0432 \u043f\u043e \u043d\u0435\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u0430\u043d\u0430\u043b\u0430 <code>incoming<\/code> \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c ClosedReceiveChannelException \u2013 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=,for%28frame%20in%20incoming\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>) (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,e.printStackTrace%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>).<\/p>\n<h4>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u044f\u043c\u0438 \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/h4>\n<p>\u0412\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043f\u043e ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 ID \u0441\u0435\u0441\u0441\u0438\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <code>ConcurrentHashMap&lt;userId, ClientSession&gt;<\/code> \u0434\u043b\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043b\u0438\u0431\u043e <code>Map&lt;userId, List&lt;ClientSession&gt;&gt;<\/code> \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, decode JWT \u0432 Cookie). Ktor \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>call.principal<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0441\u0441\u0438\u044f Cookie \u0438\u043b\u0438 JWT) \u043f\u0435\u0440\u0435\u0434 \u0430\u043f\u0433\u0440\u0435\u0439\u0434\u043e\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e <strong>\u0432\u0440\u0443\u0447\u043d\u0443\u044e<\/strong> \u043f\u0440\u0438 WebSocket handshake: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0442\u043e\u043a\u0435\u043d \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0432 \u0435\u0433\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 <code>webSocket { ... }<\/code> \u0431\u043b\u043e\u043a\u0430. \u041d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u2013 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c.<\/p>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong> \u2013 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u0437 \u0411\u0414 \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0433\u043e \u0438\u043c\u044f \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0447\u0430\u0442\u0435) \u0438 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0441\u0435\u0441\u0441\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u043a\u0443\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/strong> \u2013 \u0434\u043b\u044f \u0438\u0433\u0440\u044b \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430, \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0438 \u0442.\u043f. (\u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0438\u0437\u043d\u0430\u043a \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/strong> \u2013 timestamp \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0438\u043d\u0433\u0430, \u0444\u043b\u0430\u0433 <code>isAlive<\/code>. \u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0443\u0444\u0435\u0440\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u2013 \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0444\u0444\u043b\u0430\u0439\u043d-\u0440\u0435\u0436\u0438\u043c (\u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043f\u043e\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b), \u0441\u0435\u0441\u0441\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u0435\u0433\u043e \u043e\u0444\u043b\u0430\u0439\u043d\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0430\u0436\u043d\u043e <strong>\u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e<\/strong>: \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u0411\u0414 \u0438\u043b\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0435 \u043a\u043e\u043f\u0438\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043c\u043d\u043e\u0433\u043e). \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043b\u044e\u0447\u0435\u0439 \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u043e\u043a.<\/p>\n<h4>\u0420\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442: \u043f\u043b\u0430\u0432\u043d\u043e\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0439<\/h4>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0434\u0430\u044e\u0442 \u2013 \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0441\u0435\u0442\u044c\u044e \u043d\u0435 \u0443\u0439\u0442\u0438. \u041d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u2013 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442<\/strong>: \u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043e\u0431\u0440\u044b\u0432 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f, \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u0431\u044b\u043b \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 X \u2013 \u043f\u0440\u0438 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 X, \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u0446\u0438\u043a\u043b (\u043b\u043e\u0433\u0438\u043d, \u0432\u044b\u0431\u043e\u0440 \u043a\u043e\u043c\u043d\u0430\u0442\u044b) \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d <em>\u043e\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c<\/em>, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0439 \u0441\u0435\u0441\u0441\u0438\u0435\u0439. \u041a\u0430\u043a? \u041e\u0434\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0435\u0441\u0441\u0438\u0438<\/strong> \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u044b\u0434\u0430\u0451\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0435\u043a\u0438\u0439 <code>sessionId<\/code> (\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0432\u043d\u044b\u0439 userId+\u0432\u0440\u0435\u043c\u044f \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 UUID), \u0438 \u0435\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f, \u043e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 <code>sessionId<\/code>. \u0421\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0436\u0438\u0432\u0443\u0449\u0438\u0439 (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442) \u043a\u044d\u0448 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u043f\u043e <code>sessionId<\/code> -&gt; state, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0435\u0433\u043e \u0432 \u043d\u043e\u0432\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 cache-hit \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0451\u043b, \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043e \u0432\u044b\u0445\u043e\u0434\u0435-\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u201c\u0441\u043b\u0438\u0442\u044c\u201d \u044d\u0442\u043e \u0441 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435<\/strong>: \u041f\u0440\u043e\u0449\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0434\u0438\u043d room. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435 \u043f\u043e userId \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>Room.join(user)<\/code>. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u0445, \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u0430\u043c \u0443\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u0435\u043c\u0443 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0447\u0430\u0442\u044b), \u043b\u0438\u0431\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 (\u0447\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u2013 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0443\u0448\u0438 \u0441\u043e \u0432\u0441\u0435\u0445 \u0447\u0430\u0442\u043e\u0432 \u0441\u0440\u0430\u0437\u0443).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/strong>: \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430 \u2013 \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u043e\u0444\u043b\u0430\u0439\u043d\u0430 \u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u0438\u0439\u0442\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u0447\u0430\u0442, \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435). \u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><strong>\u0425\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/strong>: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e) \u0438\u043b\u0438 \u0432 \u0411\u0414. \u041f\u0440\u0438 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (\u0438\u043b\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e ID). \u042d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u0447\u0430\u0442\u0430\u0445: WebSocket \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f push \u0432 \u0440\u0435\u0430\u043b\u0442\u0430\u0439\u043c\u0435, \u043d\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u0435\u043b\u0430\u0435\u0442 REST API \u0432\u044b\u0437\u043e\u0432 \u0442\u0438\u043f\u0430 &#171;\u0434\u0430\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 5 \u043c\u0438\u043d\u0443\u0442&#187; \u0447\u0442\u043e\u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0444\u0444\u043b\u0430\u0439\u043d<\/strong>: \u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c (\u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c) \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043e\u0436\u0438\u0434\u0430\u044f \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 ws \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e (\u043d\u0435\u0442 close \u043a\u0430\u0434\u0440\u0430), \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u0435\u043a\u0443\u043d\u0434\u044b 30. \u0415\u0441\u043b\u0438 \u0437\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f \u2013 \u0432\u044b\u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u0431\u0443\u0444\u0435\u0440. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 (\u0435\u0441\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043f\u0440\u0438\u0448\u0451\u043b \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0443\u0437\u0435\u043b \u2013 \u0431\u0443\u0444\u0435\u0440 \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u043d\u0430\u0434\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043e\u0431\u0449\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435).<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u043e\u0431 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0430\u043d\u0438\u0438<\/strong>: \u0432 \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0433\u0440\u043e\u043a \u043e\u0442\u0432\u0430\u043b\u0438\u043b\u0441\u044f \u2013 \u043e\u043d \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f &#171;\u0432\u0438\u0441\u0438\u0442&#187;, \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0448\u0435\u0434\u0448\u0438\u043c. \u041f\u0440\u0438 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0438\u0433\u0440\u043e\u0432\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0442\u0432\u0430\u043b \u043d\u0430 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u2013 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 30+ \u0441\u0435\u043a\u0443\u043d\u0434 \u2013 \u0438\u0433\u0440\u043e\u043a \u0443\u0436\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b \u043f\u043e\u0437\u0438\u0446\u0438\u044e. \u042d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Backoff \u043f\u0440\u0438 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0435<\/strong>: \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438\u043b\u0438 \u0441\u0435\u0442\u0438, \u0441\u043e\u0442\u043d\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u0430\u0432\u0438\u043d\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u044d\u043aoff (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 0.5s, 1s, 2s, 5s, &#8230; \u0434\u043e \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430) \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430<\/strong>: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u0440\u044b\u0432\u0430 (onClose) \u0441\u0440\u0430\u0437\u0443 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043d\u043e\u0432\u044b\u0439 WebSocket. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043d\u0438\u0442 <code>lastMessageId<\/code> \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041f\u0440\u0438 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: <code>{ type: \"RESUME\", lastId: 123 }<\/code>. \u0421\u0435\u0440\u0432\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 RESUME, \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043b\u0438\u0431\u043e <code>RESUME_OK<\/code> (\u0438 \u0437\u0430\u0442\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043b\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0434\u043e 123), \u043b\u0438\u0431\u043e <code>RESUME_FAIL<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0443\u0436\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430), \u0442\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0431\u044f\u0437\u0430\u043d \u0437\u0430\u043d\u043e\u0432\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f (\u0447\u0435\u0440\u0435\u0437 REST \u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u0440\u0435\u0444\u0440\u0435\u0448 \u0434\u0430\u043d\u043d\u044b\u0445). \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430\u043c \u0442\u0438\u043f\u0430 Socket.IO \u0438\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043a\u0430\u043a Ably. \u041e\u043d \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0434\u0430\u0451\u0442 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 UX.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0436\u0435 \u0441\u0438\u0441\u0442\u0435\u043c (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u2013 \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0430\u0442 \u0431\u0435\u0437 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438) \u043c\u043e\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u043c \u0432\u0445\u043e\u0434\u043e\u043c \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u043b\u0438 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b.<\/p>\n<h3>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0441\u0442\u0451\u0442, \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0443\u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u043b\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u0438. <strong>\u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong> WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u2013 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e WebSocket \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f <em>\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442<\/em>. \u041d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><strong>Sticky sessions (\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0441\u0435\u0441\u0441\u0438\u0439)<\/strong>: \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 (Nginx, HAProxy, AWS ELB) \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0436\u0438\u043c, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439, \u0447\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u0439\u0434\u0443\u0442 \u043d\u0430 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u0440\u0432\u0435\u0440. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 HTTP \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c cookie \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0434\u043b\u044f WebSocket \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0443 \u043f\u043e IP \u0438\u043b\u0438 \u043f\u043e\u0440\u0442\u0443. Sticky-\u0441\u0435\u0441\u0441\u0438\u0438 <em>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b<\/em>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0444\u0440\u0435\u0439\u043c\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u043e\u0434\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=As%20we%20mentioned%20earlier%2C%20sticky,server%20becomes%20overloaded%20or%20fails\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>). \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u043c\u0438\u043d\u0443\u0441: \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e (\u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b \u043d\u0430\u0431\u0440\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u00ab\u0442\u044f\u0436\u0451\u043b\u044b\u0445\u00bb \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u2013 \u043d\u0435\u0442) (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=clients%2C%20or%20sticky%20sessions%2C%20are,regional%20failure%2C%20we%20of%20course\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>). \u041d\u0443\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0431\u0430\u043b\u0430\u043d\u0441\u043e\u043c: \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0443\u043c\u0435\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d, \u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c stickiness \u0438\u043b\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/strong>: \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0438\u0433\u0440, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0447\u0430\u0442\u043e\u0432. \u0422\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0440\u0430\u0437\u043d\u044b\u043c endpoints (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>game.example.com<\/code> \u0438 <code>chat.example.com<\/code>). \u042d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043d\u043e \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440. \u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0430\u0449\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0443\u0437\u043b\u044b (\u043a\u043b\u0430\u0441\u0442\u0435\u0440).<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0449\u0438\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/strong>: \u043f\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u043e\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043b\u044e\u0431\u0430\u044f \u043d\u043e\u0434\u0430 \u043c\u043e\u0433\u043b\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0440\u0443\u0434\u043d\u043e, \u043d\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432\u0435\u0449\u0438 \u2013 \u0441\u043f\u0438\u0441\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043d\u0430\u0442 \u2013 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (\u0411\u0414\/\u043a\u044d\u0448). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 Redis \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u043c\u043d\u0430\u0442 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u2013 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0422\u043e\u0433\u0434\u0430 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 user, \u0438\u043b\u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u2013 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a Redis. <strong>\u041e\u0434\u043d\u0430\u043a\u043e<\/strong> \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0443 \u2013 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430; \u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0443\u0437\u043b\u0430\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>Redis Pub\/Sub \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong>: \u041a\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0432\u0441\u0435\u043c? \u0420\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0441\u0435\u0440\u0432\u0435\u0440-\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 Redis (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>PUBLISH room123 \"{...json...}\"<\/code>). \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u044b (<code>SUBSCRIBE room123<\/code>) \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u2013 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u044e\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430\u043c \u043a\u043e\u043c\u043d\u0430\u0442\u044b. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u042d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0447\u0430\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Socket.IO \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f Redis \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e). <strong>\u041c\u0438\u043d\u0443\u0441\u044b<\/strong>: \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Redis (\u043e\u0431\u044b\u0447\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430, \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b) \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 Redis. \u0412 \u0446\u0435\u043b\u043e\u043c, Redis \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e <strong>Redis Pub\/Sub \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/strong> \u2013 \u0435\u0441\u043b\u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d \u043e\u0442 Redis, \u043e\u043d \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (<a href=\"https:\/\/ably.com\/blog\/scaling-pub-sub-with-websockets-and-redis#:~:text=Message%20persistence\" rel=\"noopener noreferrer nofollow\">Scaling Pub\/Sub with WebSockets and Redis<\/a>). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0441\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u0411\u0414.<\/p>\n<\/li>\n<\/ul>\n<p>(<span>image<\/span>) <em>\u0421\u0445\u0435\u043c\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/em> \u041a\u043b\u0438\u0435\u043d\u0442\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a (\u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 sticky sessions) \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 Ktor-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0431\u0440\u043e\u043a\u0435\u0440 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Redis Pub\/Sub) \u2013 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u044b, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445. \u041e\u0431\u0449\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0438\u0441\u0442\u043e\u0440\u0438\u044f, \u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u0438 \u043f\u0440.), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u0440\u0430\u043d\u0438\u0442\u044c, \u043a \u043a\u0430\u043a\u043e\u0439 \u043d\u043e\u0434\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0451\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c). \u0422\u0430\u043a\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c: \u043f\u0440\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u0441\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0411\u0414.<\/p>\n<p><strong>Sharding (\u0448\u0430\u0440\u0434\u0438\u043d\u0433)<\/strong>: \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0438\u0433\u0440\u043e\u0432\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c \u043d\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0430 <strong>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c (\u0441\u0442\u0440\u0430\u043d\u0430, ID) \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u043e\u0434\u0441\u0435\u0440\u0432\u0435\u0440. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 DNS (\u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u0433\u0438\u043e\u043d\u043e\u0432) \u0438\u043b\u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u0443\u043c\u0435\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c shard. \u0412 \u0438\u0442\u043e\u0433\u0435, \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0448\u0430\u0440\u0434\u0430, \u0438 \u043c\u0435\u0436\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0434\u0438\u0437\u0430\u0439\u043d (\u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u043a\u0430\u043a \u0431\u044b\u0442\u044c \u0435\u0441\u043b\u0438 \u0434\u0432\u0430 \u0434\u0440\u0443\u0437\u0435\u0439 \u043f\u043e\u043f\u0430\u043b\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0448\u0430\u0440\u0434\u044b \u2013 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0432\u0435\u0434\u0451\u0448\u044c \u0438\u0445 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c).<\/p>\n<p><strong>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c<\/strong>: \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0433\u0435\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0447\u0430\u0442), \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0431\u043b\u0438\u0436\u0435 \u043a \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0444\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0433\u0435\u043e-\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430: \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440\u0430\u0445, \u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u0430 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u044f\u0442 <strong>\u0434\u0435\u0440\u0435\u0432\u043e \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u0432<\/strong> \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438 (Ably, Pusher, etc), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0435\u0440\u0443\u0442 \u044d\u0442\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0441\u0435\u0431\u044f (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=while%20preventing%20servers%20from%20being,strategies%2C%20you%20can%20quickly%20run\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>) (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=Use%20load%20balancers%20globally\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>). \u0414\u043b\u044f mid-level \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442; \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0433\u0438\u043e\u043d\u0430 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043d\u0451\u043c, \u0430 \u0443\u0436 \u043f\u043e\u0442\u043e\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044e\u0442 \u0433\u0435\u043e\u0433\u0440\u0430\u0444\u0438\u0435\u0439.<\/p>\n<p><strong>\u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c<\/strong>: \u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0451\u0442 \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0441\u0442\u0440\u043e\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u0421 WebSocket \u044d\u0442\u043e tricky: \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0443\u043f\u0430\u043b, \u0432\u0441\u0435 \u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043e\u043c \u0440\u0432\u0443\u0442\u0441\u044f. \u0411\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0451\u0442 \u0442\u0440\u0430\u0444\u0438\u043a \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0437\u043b\u044b, \u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f. \u0417\u0434\u0435\u0441\u044c \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0440\u0443\u0447\u0430\u0435\u0442 \u0443\u043c\u043d\u0430\u044f \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, AWS ELB \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 &#171;\u0437\u0430\u0440\u0435\u0437\u0430\u0442\u044c&#187; \u0432\u0441\u0435 TCP \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u044b \u043a \u0443\u043c\u0435\u0440\u0448\u0435\u043c\u0443 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0443, \u0447\u0442\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u0441\u044f \u0438, \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u043a\u0443\u043d\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043a\u0440\u043e\u043c\u0435 \u043a\u0440\u0430\u0442\u043a\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u044b\u0432\u0430). \u0422\u0430\u043a\u0436\u0435, <strong>\u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433<\/strong> \u0438 <strong>\u0430\u0432\u0442\u043e\u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u043d\u0438\u0435<\/strong> (auto-scaling) \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439, \u0430 \u043f\u0440\u0438 \u0441\u043f\u0430\u0434\u0435 \u2013 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e: <em>\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435<\/em>, \u043d\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043f\u043e\u043a\u0430 \u0441\u043e\u0442\u043d\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u2013 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0431\u0435\u0437 Redis. \u041d\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 MessageBroker (\u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 publish\/subscribe) \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e-\u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 (\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430), \u0430 \u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u2013 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 Redis, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434.<\/p>\n<h3>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438<\/h3>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0436\u0438\u0432\u0451\u0442 \u0432 \u0432\u0430\u043a\u0443\u0443\u043c\u0435 \u2013 \u0435\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>: \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0447\u0430\u0442\u0430 \u2013 \u044d\u0442\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0441\u043f\u0438\u0441\u043a\u0438 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u043e\u0432; \u0434\u043b\u044f \u0438\u0433\u0440 \u2013 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u0432, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u0430\u0442\u0447\u0435\u0439; \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u2013 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0442.\u043f. Ktor \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u0421\u0423\u0411\u0414 \u2013 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 JDBC (\u0447\u0435\u0440\u0435\u0437 Kotlin Exposed \u0438\u043b\u0438 JPA\/Hibernate) \u0438\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u044b (R2DBC, Mongo async driver \u0438 \u0442.\u0434.). \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2013 <strong>\u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong> \u043f\u043e\u0442\u043e\u043a Netty event loop \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438. \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 (JDBC) \u2013 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0439\u0442\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (\u0447\u0435\u0440\u0435\u0437 <code>withContext(Dispatchers.IO)<\/code>). \u041b\u0443\u0447\u0448\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 (\u0438\u0445 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u043a\u044d\u0448\u0435), \u0430 \u043a\u0430\u043a\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0435\u0440\u0432\u0438\u0441\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>: \u0412\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2013 \u0438\u0445 \u0432\u0430\u0436\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0439 (\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u043e\u0433\u0438 \u043d\u0430 Elastic, \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 Prometheus\/Grafana) \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c JSON \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (\u0442\u0438\u043f\u0430 &#171;user_sent_message&#187;, &#171;user_joined_room&#187;) \u0432 \u0431\u0440\u043e\u043a\u0435\u0440 (Kafka, RabbitMQ) \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0432\u043d\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042d\u0442\u043e \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u0430\u0434\u0435\u043d\u0438\u044f) \u0441\u0442\u043e\u0438\u0442 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/strong>: \u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u044f\u0436\u0451\u043b\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0435\u0451 \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 WebSocket-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0434\u043e\u043b\u0433\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u043c\u0443 API, \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430 email \u2013 \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 RabbitMQ\/Kafka, \u0430 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0447\u0442\u043e &#171;\u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u043d\u044f\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f&#187;. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u043b\u0438 \u043f\u0440\u0438\u0441\u043b\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0442 \u0436\u0435 WebSocket, \u0438\u043b\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u0438\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (Kafka clients, AMQP clients), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 Kotlin \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 pool \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u043d\u0435\u0448\u043d\u0438\u0435 API \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/strong>: \u0412\u0430\u0448 WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a, \u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u0430\u0442\u0447\u043c\u0435\u0439\u043a\u0438\u043d\u0433\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d \u0432\u044b\u043d\u0435\u0441\u0435\u043d \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0438 \u0442.\u0434.). \u0412\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 (Ktor Client) \u0438\u043b\u0438 gRPC async stub, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0438 \u043f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0435\u0441\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u0437 \u043a\u044d\u0448\u0430).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0441\u0442\u044c<\/strong>: \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0411\u0414 \u0432 real-time \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0440\u0435\u0434\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u0447\u0442\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0411\u0414? \u0420\u0430\u0437\u0443\u043c\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c (\u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c), \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443. \u041e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u041f\u0438\u0448\u0443\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u0431\u0430\u0437\u0443 <em>\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e<\/em> \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043f\u043e WebSocket. \u0422\u043e \u0435\u0441\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0447\u0442\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0411\u0414 (\u0432 \u0444\u043e\u043d\u0435) \u0438 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u0435. \u041c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u2013 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0442\u0435\u0440\u0438 \u0435\u0441\u0442\u044c (\u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0443\u043f\u0430\u0434\u0451\u0442 \u0440\u043e\u0432\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442), \u043d\u043e \u0437\u0430\u0442\u043e \u0447\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u0422\u0443\u0442 \u0431\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e. \u0412 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f, \u043f\u043e\u0442\u043e\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e\u0435 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043b\u0430\u0434\u0443\u0442\u0441\u044f \u0432 persistent-\u043e\u0447\u0435\u0440\u0435\u0434\u044c (Kafka), \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044f\u0441\u044c \u043e\u0442\u0442\u0443\u0434\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u0448\u043b\u044e\u0442\u0441\u044f. \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043b\u0438\u0431\u043e \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f, \u0438 \u0440\u0430\u0437\u043e\u0448\u043b\u0451\u0442\u0441\u044f, \u043b\u0438\u0431\u043e \u043d\u0438\u0447\u0435\u0433\u043e (\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c). \u041d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 (\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443).<\/p>\n<\/li>\n<\/ul>\n<p><strong>Backpressure \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c<\/strong>: \u0415\u0441\u043b\u0438 \u0411\u0414 \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c, \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u043d\u0435 &#171;\u043f\u043e\u0434\u0432\u0435\u0441\u0438\u043b\u043e&#187; \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 WebSocket-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0442\u0443\u0442 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u2013 \u043f\u043e\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u043f\u043e\u0434\u0432\u0435\u0448\u0435\u043d, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u0449\u0438\u0439 \u043f\u0443\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043a \u0411\u0414 \u0437\u0430\u0431\u0438\u0442, \u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c. \u041d\u0443\u0436\u043d\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438 (\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0443\u043b\u0430, \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432) \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0411\u0414 \u043e\u0447\u0435\u043d\u044c \u043b\u0430\u0433\u0430\u0435\u0442, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u044c (\u0441 \u0440\u0438\u0441\u043a\u043e\u043c \u043f\u043e\u0442\u0435\u0440\u0438, \u043d\u043e \u0437\u0430\u0442\u043e \u043d\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u0447\u0430\u0442).<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <em>best practices<\/em> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><strong>1) \u041c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 WebSocket-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435<\/strong>: \u043d\u0435 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 <code>for(frame in incoming)<\/code>. \u041b\u0443\u0447\u0448\u0435 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, parse JSON -&gt; <code>chatService.processMessage(user, message)<\/code>. \u041f\u0443\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0451\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0430 \u043e\u043d\u0438 \u0443\u0436\u0435 \u0440\u0435\u0448\u0430\u044e\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c (\u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0411\u0414, \u043e\u0442\u043e\u0441\u043b\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438 \u0442.\u0434.). \u042d\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>2) \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/strong>: \u0412\u0441\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f (\u0411\u0414, HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b) \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>suspend<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u2013 \u043e\u0431\u0435\u0440\u043d\u0438\u0442\u0435 \u0432 <code>withContext(Dispatchers.IO)<\/code>. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442 \u0437\u0430\u0442\u043e\u0440\u043c\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. Ktor \u0438 coroutines \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, \u043d\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043e\u043d\u0438 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0442\u043e\u043a \u043d\u0430 <code>suspend<\/code> \u0442\u043e\u0447\u043a\u0430\u0445 (<a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/09\/ktor-101-efficient-jvm-http-toolkit\/#:~:text=The%20Ktor%20project%20started%20as,This\" rel=\"noopener noreferrer nofollow\">Ktor 101: Efficient JVM HTTP Toolkit | The IntelliJ IDEA Blog<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong>3) \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/strong>: \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0438\u0442\u0435 \u0446\u0438\u043a\u043b \u0447\u0442\u0435\u043d\u0438\u044f \u0432 <code>try\/catch<\/code> \u043d\u0430 <code>ClosedReceiveChannelException<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 Exception (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=,for%28frame%20in%20incoming\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>) (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,e.printStackTrace%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (remove session, notify others). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\">try {     for(frame in incoming) { ... } } catch(e: ClosedReceiveChannelException) {     \/\/ onClose } catch(e: Throwable) {     \/\/ onError } finally {     room.leave(session); sessions.remove(userId) } <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0432\u044b \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>4) \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b<\/strong>: \u0417\u0430\u0434\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0435 \u043b\u0438\u043c\u0438\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><code>maxFrameSize<\/code> \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 WebSockets, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u0437\u0430\u043b\u0438\u043b \u0432\u0430\u043c 10MB \u043e\u0434\u043d\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=,could%20be%20received%20or%20sent\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u2013 \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0442\u0435\u043d KB \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c throttling: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c &gt; N \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u0435\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0448\u043b\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u043e \u2013 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u043b \u0432\u0441\u044e \u043f\u043e\u043b\u043e\u0441\u0443).<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440\u044b \u043a\u0430\u043d\u0430\u043b\u043e\u0432 (\u0431\u0443\u0444\u0435\u0440\u043e\u0432) \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443: \u0435\u0441\u043b\u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0448\u043a\u0432\u0430\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0443\u0439\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u043d\u043e \u043d\u0435 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u044a\u0435\u0441\u0442.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>5) \u0421\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438<\/strong>: \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 sticky-\u0441\u0435\u0441\u0441\u0438\u0438, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0439\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 sticky \u043f\u043e IP \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0442\u044f\u0436\u0451\u043b\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0440\u0443\u043f\u043d\u043e\u0433\u043e NAT \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440. \u0418\u043d\u043e\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c cookie-based stickiness \u0441 hash, \u0438\u043b\u0438 <strong>consistent hashing<\/strong> \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=clients%2C%20or%20sticky%20sessions%2C%20are,regional%20failure%2C%20we%20of%20course\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>) \u2013 \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e. \u041d\u043e \u0434\u0430\u0436\u0435 \u0442\u043e\u0433\u0434\u0430, \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0447\u0438\u0441\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u0442\u0440\u0430\u0444\u0438\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p><strong>6) \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435<\/strong>: \u042d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u0432\u0435\u0442 \u043f\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043d\u043e \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c. \u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u043e\u0432\u0438\u0442\u044c <code>onClose<\/code> \u0438 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e \u0441 \u043f\u0430\u0443\u0437\u0430\u043c\u0438 (backoff). \u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0445\u0435 \u2013 \u0437\u0430\u043d\u043e\u0432\u043e \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0435\u0439\u043b\u043e\u0432\u0435\u0440\u0430 (\u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440) (<a href=\"https:\/\/dev.to\/ably\/when-and-how-to-load-balance-websockets-at-scale-5cnk#:~:text=Implement%20automatic%20reconnection%20logic\" rel=\"noopener noreferrer nofollow\">When and how to load balance WebSockets at scale &#8212; DEV Community<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong>7) \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/strong>: \u0428\u0438\u0444\u0440\u0443\u0439\u0442\u0435 \u0442\u0440\u0430\u0444\u0438\u043a (wss:\/\/), \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0435\u0437 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u044c\u0442\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 (\u0432 Ktor \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c Origin header \u0434\u043b\u044f WebSocket, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a\u0430\u044f \u043d\u0430\u0434\u0451\u0436\u043d\u0430\u044f \u0437\u0430\u0449\u0438\u0442\u0430). \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u2013 \u043d\u0435 \u0434\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u0441\u043b\u0430\u043b JSON \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 JWT \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0441\u0440\u043e\u043a\u0438 \u0433\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043a\u0435\u043d\u0430, \u0438 \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d \u043e\u0442\u043e\u0437\u0432\u0430\u043d \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u2013 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e \u0431\u0430\u0437\u0435 \u0447\u0435\u0440\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 TTL \u0442\u043e\u043a\u0435\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0441\u044f).<\/p>\n<\/li>\n<li>\n<p><strong>8) \u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439<\/strong>: \u0420\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u044b\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f WebSocket (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, K6, Gatling, NBomber) \u2013 \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 1000 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u0448\u043b\u0451\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u043a\u0430\u043a \u043f\u043e\u0432\u0435\u0434\u0451\u0442 \u0441\u0435\u0431\u044f \u0441\u0435\u0440\u0432\u0435\u0440: \u043d\u0435 \u0440\u0430\u0441\u0442\u0451\u0442 \u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u044c, \u0443\u0441\u043f\u0435\u0432\u0430\u044e\u0442 \u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u0438\u0442\u044c, \u043d\u0435\u0442 \u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0422\u0430\u043a \u0432\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0443\u0437\u043a\u0438\u0435 \u043c\u0435\u0441\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 10k \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u2013 \u0442\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0434\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c heap \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 GC.<\/p>\n<\/li>\n<li>\n<p><strong>9) \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f<\/strong>: \u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 INFO \u043b\u043e\u0433\u043e\u0432 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\/\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (\u0441 userId, \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439), \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f), \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0430\u043c\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0438\u0445 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u2013 \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0441\u0442\u044c). \u041d\u043e \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u2013 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 (Micrometer \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 Ktor) \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430: \u0447\u0438\u0441\u043b\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439, \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a\u0430\u043d\u0430\u043b\u0430, \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0447\u0438\u0441\u043b\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443. \u042d\u0442\u0438 \u0446\u0438\u0444\u0440\u044b \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>10) \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u044f\u0439\u0442\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/strong>: \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 (\u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u0434). \u0417\u0430\u0442\u0435\u043c, \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430, \u0432\u043d\u0435\u0434\u0440\u044f\u0439\u0442\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438, \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u043e CPU \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e JSON \u2013 \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 (Ktor \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 CBOR, ProtoBuf \u0438 \u0442.\u0434. (<a href=\"https:\/\/ktor.io\/docs\/server-websocket-serialization.html#:~:text=WebSockets%20serialization%20in%20Ktor%20Server,JSON%2C%20XML%2C%20CBOR%2C%20and\" rel=\"noopener noreferrer nofollow\">WebSockets serialization in Ktor Server<\/a>)). \u0418\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u0438 100\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432\u0430\u0448 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u2013 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 SharedFlow \u0438\u043b\u0438 \u0440\u0430\u0437\u0431\u0435\u0439\u0442\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u043d\u0430 \u043f\u043e\u0434-\u0433\u0440\u0443\u043f\u043f\u044b. <strong>\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u0443\u0439\u0442\u0435<\/strong> \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0439\u0442\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043e\u0442\u043c\u0435\u0442\u0438\u043c: \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u2013 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0441\u043e\u0447\u0435\u0442\u0430\u044e\u0449\u0430\u044f \u043d\u044e\u0430\u043d\u0441\u044b \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Kotlin \u0438 Ktor, \u043c\u043e\u0436\u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b. \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0411\u043e\u0433\u0430\u0442\u0430\u044f \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0430 (Redis, Kafka, \u0431\u0430\u0437\u044b) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043e\u0431\u0449\u0438\u0439 \u0431\u044d\u043a\u0435\u043d\u0434. \u0421\u043b\u0435\u0434\u0443\u044f \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c WebSocket-\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443, \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 realtime-\u043e\u043f\u044b\u0442.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/898700\/\"> https:\/\/habr.com\/ru\/articles\/898700\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Ktor<\/strong> \u2013 \u044d\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u044b \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <strong>\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c Kotlin<\/strong> Ktor \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e WebSocket-\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (<a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/09\/ktor-101-efficient-jvm-http-toolkit\/#:~:text=Thanks%20to%20coroutines%2C%20Ktor%20makes,simple%20echo%20server%20with%20WebSockets\" rel=\"noopener noreferrer nofollow\">Ktor 101: Efficient JVM HTTP Toolkit | The IntelliJ IDEA Blog<\/a>). \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0435\u0441\u0441\u0438\u0439, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043a\u043e\u043c\u043d\u0430\u0442 (\u0447\u0430\u0442\u043e\u0432, \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043b\u043e\u0431\u0431\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u043d\u0433\u0430), \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (heartbeat, \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u044b), \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u0438\u0437 \u0431\u043e\u0435\u0432\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430.<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Ktor<\/h3>\n<p>\u041f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432\u0430\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0438 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0441\u0435\u0442\u0438 (WebSocket-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b)<\/strong>: \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0412 Ktor \u044d\u0442\u043e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b <code>webSocket(...)<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>routing { ... }<\/code>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443-\u0441\u0435\u0441\u0441\u0438\u044e. \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0435\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435\/\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 (\u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b)<\/strong>: \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u043c, \u0433\u0435\u0439\u043c\u043f\u043b\u0435\u0439 \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u043a\u043e\u043c\u043d\u0430\u0442, \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\/\u0441\u0435\u0441\u0441\u0438\u0439 \u0438 \u0434\u0440. \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 WebSocket-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u2013 \u043e\u043d\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0439<\/strong>: \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u044d\u0448\u0435\u043c, \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 API \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u043c\u0438. \u042d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u0442.\u0434. \u041e\u043d \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442 WebSocket-\u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u2013 \u0432\u0435\u0440\u0445\u043d\u0438\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0411\u0414, Redis, Kafka \u0438 \u043f\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u044c: \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439) \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043c\u043d\u0430\u0442, \u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u043e\u0434 \u0441\u0435\u0441\u0441\u0438\u0439.<\/p>\n<h4>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/h4>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0443 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u044d\u0442\u0430\u043f\u044b:<\/p>\n<ol>\n<li>\n<p><strong>Handshake \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> \u2013 Ktor \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u0440\u0435\u0434\u0435\u043d\u0448\u0430\u043b\u044b. Ktor \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 Authorization \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u044f WebSocket, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u2013 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 URL \u0438\u043b\u0438 cookie \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438. \u041f\u0440\u0438 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0435 \u2013 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438<\/strong> \u2013 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, userId, \u0438\u043c\u044f) \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b (\u0435\u0433\u043e WebSocket-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043a\u0430\u043d\u0430\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435). \u0421\u0435\u0441\u0441\u0438\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u043c \u0440\u0435\u0435\u0441\u0442\u0440\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435<\/strong> \u2013 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u044b (\u0447\u0430\u0442-\u043a\u043e\u043c\u043d\u0430\u0442\u0430, \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043c\u0430\u0442\u0447), \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 URL (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>ws:\/\/server\/game?roomId=X<\/code>) \u0438\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043a\u043e\u043c\u043d\u0430\u0442 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438<\/strong> \u2013 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b: \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439). \u042d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <strong>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438<\/strong>. Ktor \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <strong>\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b<\/strong> \u0438 <strong>\u043a\u0430\u043d\u0430\u043b\u044b<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/strong> \u2013 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u044b\u0432\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u043c) \u0441\u0435\u0440\u0432\u0435\u0440 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u0438\u0437 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445, \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u2013 \u0447\u0442\u043e\u0431\u044b \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043e\u043f\u043e\u0432\u0435\u0441\u0442\u0438\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445) \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0415\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u0440\u043e \u0440\u0435\u043a\u043e\u043d\u043d\u0435\u043a\u0442).<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 Ktor \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442-\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439, \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 <strong>\u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0435\u0441\u0441\u0438\u0438<\/strong> \u0442\u0438\u043f\u0430 <code>DefaultWebSocketServerSession<\/code> (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=Inside%20the%20,are%20available%20within%20the%20block\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). \u042d\u0442\u0430 \u0441\u0435\u0441\u0441\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u043a\u0430\u043d\u0430\u043b\u0430: <code>incoming<\/code> \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432 \u0438 <code>outgoing<\/code> \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445. \u0412 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>for(frame in incoming) { ... }<\/code> \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 <code>send(...)<\/code> \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0430 \u043d\u0430 Ktor:<\/p>\n<pre><code class=\"kotlin\">routing {     webSocket(\"\/ws\") {         \/\/ \u041f\u0440\u0438\u043c\u0435\u0440: \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         send(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0435 \u0438\u043c\u044f:\")         for (frame in incoming) {             frame as? Frame.Text ?: continue             val text = frame.readText()             if (text.equals(\"bye\", ignoreCase=true)) {                 close(CloseReason(CloseReason.Codes.NORMAL, \"Client said BYE\"))             } else {                 send(\"\u042d\u0445\u043e: \u0412\u044b \u043f\u0440\u0438\u0441\u043b\u0430\u043b\u0438 \\\"$text\\\"\")             }         }     } } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 (\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f echo-\u0441\u0435\u0440\u0432\u0435\u0440\u0430) \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 <code>incoming<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>send<\/code> \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u0440\u0430\u0437\u0431\u043e\u0440 JSON-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0432\u044b\u0437\u043e\u0432\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u0430\u043c \u0438 \u0442.\u043f.<\/p>\n<h3>Kotlin Coroutines \u0438 Channels \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439<\/h3>\n<p><strong>\u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b Kotlin<\/strong> \u2013 \u0441\u0435\u0440\u0434\u0446\u0435\u0432\u0438\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 Ktor. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u00ab1 \u043f\u043e\u0442\u043e\u043a \u043d\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u00bb, \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0442\u044b\u0441\u044f\u0447 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u043c \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u041a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0411\u0414, \u043f\u043e\u0442\u043e\u043a \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442 \u2013 \u043e\u043d \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 <strong>\u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430<\/strong> \u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0434\u0430\u0436\u0435 \u043d\u0430 4-8 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u043e\u0432.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <strong>\u043a\u0430\u043d\u0430\u043b\u044b<\/strong> (Channels) \u2013 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u044b \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u0440\u0438\u0451\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/strong>: \u0425\u043e\u0442\u044f \u043c\u043e\u0436\u043d\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d-\u0446\u0438\u043a\u043b\u0435 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c, \u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0430\u0441\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0438 \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>\u043a\u0430\u043d\u0430\u043b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041e\u0434\u0438\u043d \u0444\u043e\u043d\u043e\u0432\u044b\u0439 coroutine \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 coroutine \u2013 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u043a\u0430\u043d\u0430\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <code>session.send<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435\u0436\u0451\u0441\u0442\u043a\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u2013 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043a\u0430\u043d\u0430\u043b \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u043e\u0434\u0438\u043d coroutine \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0438\u0445, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0433\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>Broadcaster (Actor)<\/strong>: \u0414\u0440\u0443\u0433\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u2013 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0430\u043a\u0442\u043e\u0440<\/strong> (actor) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0410\u043a\u0442\u043e\u0440 \u2013 \u044d\u0442\u043e coroutine \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u043c, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439) \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f: \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u0445, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 (\u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0441\u044f\/\u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f) \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u043e\u0440 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 coroutine \u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 <code>Channel&lt;RoomEvent&gt;<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>\u043a\u0430\u043d\u0430\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u0438<\/strong>:<\/p>\n<pre><code class=\"kotlin\">class ClientSession(val session: DefaultWebSocketServerSession) {     val outgoing: Channel&lt;String&gt; = Channel(capacity = 16)  \/\/ \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439      init {         \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c coroutine-\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c         GlobalScope.launch {             for (msg in outgoing) {                 session.send(msg)  \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 JSON             }         }     } } <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>ClientSession(session)<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>ConcurrentHashMap<\/code> \u043f\u043e ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0445\u043e\u0447\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 <code>clientSession.outgoing.trySend(message)<\/code> (\u0438\u043b\u0438 <code>launch { clientSession.outgoing.send(message) }<\/code> \u0434\u043b\u044f suspend-\u0432\u044b\u0437\u043e\u0432\u0430). \u0422\u0430\u043a\u043e\u0435 decoupling \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u043d\u0430\u043b (\u0434\u0430\u0436\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430\/\u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430), \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e \u0441\u0435\u0442\u0438. \u041a\u043e\u0440\u0443\u0442\u0438\u043d-\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438<\/strong> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443\u0437\u043a\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u2013 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e \u0441\u0435\u0442\u0438 \u2013 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u044e. \u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 (\u043d\u0438\u0437\u043a\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0438\u043b\u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u2013 \u0435\u0433\u043e \u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u0438 \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0451\u043c\u043a\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0438\u043b\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439. \u042d\u0442\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443: \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445, \u0442.\u043a. \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e.<\/p>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u043a\u0430\u043d\u0430\u043b\u0430\u043c \u043c\u043e\u0433 \u0431\u044b \u0431\u044b\u0442\u044c <code>SharedFlow<\/code>\/<code>StateFlow<\/code> \u0438\u0437 kotlinx.coroutines. \u0412 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Ktor \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>MutableSharedFlow<\/strong> \u0434\u043b\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0432\u0435\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044f\u043c (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=Example%3A%20Handle%20multiple%20sessions\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>) (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,job.cancel%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). SharedFlow \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u00ab\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435\u0439, \u043e\u0434\u0438\u043d \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u00bb \u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0431\u043e\u0440\u0449\u0438\u043a (<code>sharedFlow.collect<\/code>) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c WebSocket-\u0441\u0435\u0441\u0441\u0438\u0438, \u0438 \u043f\u0440\u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u043d\u043e <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u043c<\/strong> \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0441\u0435\u0441\u0441\u0438\u0439 (<a href=\"https:\/\/ktor.io\/docs\/server-websockets.html#:~:text=webSocket%28,job.cancel%28%29%20%7D\" rel=\"noopener noreferrer nofollow\">WebSockets in Ktor Server | Ktor Documentation<\/a>). \u042d\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u0437\u0430\u0431\u043e\u0442 \u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e SharedFlow \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043c\u043d\u0430\u0442 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 (\u0442.\u043a. \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u044b), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c\u0441\u044f. \u0412\u044b\u0431\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 Channel \u0438 Flow \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u043a\u0443\u0441\u0430 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438; \u0434\u043b\u044f middle-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043e\u0431\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<h3>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043e\u043c\u043d\u0430\u0442<\/h3>\n<p><strong>\u041a\u043e\u043c\u043d\u0430\u0442\u044b<\/strong> \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0447\u0430\u0442\u043e\u0432, \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u0435\u0440\u043d\u044b\u0445 \u0438\u0433\u0440, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438 \u0442.\u0434. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e, \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u2013 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-455160","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455160"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455160\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}