{"id":248507,"date":"2015-01-22T13:47:03","date_gmt":"2015-01-22T09:47:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=248507"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=248507","title":{"rendered":"<span class=\"post_title\">WebSocket RPC \u0438\u043b\u0438 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0436\u0438\u0432\u043e\u0435 WEB \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/960\/20a\/2f5\/96020a2f5946495699ac1e1816cc6a6d.jpg\"\/><\/p>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 WebSocket. \u0422\u043e\u0447\u043d\u0435\u0435 \u043d\u0435 \u043e \u0441\u0430\u043c\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438, \u0430 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u042f \u0434\u0430\u0432\u043d\u043e \u0441\u043b\u0435\u0436\u0443 \u0437\u0430 \u043d\u0435\u0439. \u0415\u0449\u0435 \u043a\u043e\u0433\u0434\u0430 \u0432 2011 \u0433\u043e\u0434\u0443 \u043e\u0434\u0438\u043d \u043c\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u0433\u0430 \u043f\u0440\u0438\u0441\u043b\u0430\u043b \u043c\u043d\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <a href=\"https:\/\/tools.ietf.org\/html\/rfc6455\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442<\/a>, \u043f\u0440\u043e\u0431\u0435\u0436\u0430\u0432 \u0433\u043b\u0430\u0437\u0430\u043c\u0438, \u044f \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0441\u0441\u0442\u0440\u043e\u0438\u043b\u0441\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0443\u0442\u043e, \u0438 \u044f \u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445, \u044f \u0443\u0436\u0435 \u0431\u0443\u0434\u0443 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0430 \u0447\u0442\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043f\u0435\u043d\u0441\u0438\u044e. \u041d\u043e \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u0430\u043a, <a href=\"http:\/\/caniuse.com\/#feat=websockets\">\u0438 \u043a\u0430\u043a \u0433\u043b\u0430\u0441\u0438\u0442 caniuse.com<\/a> WebSocket \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Opera Mini (\u043d\u0430\u0434\u043e \u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u043a\u0442\u043e-\u043b\u0438\u0431\u043e \u0432\u0438\u0434\u0435\u043b Opera Mini).<\/p>\n<p>  \u041a\u0442\u043e \u0442\u0440\u043e\u0433\u0430\u043b WebSocket\u044b \u0440\u0443\u043a\u0430\u043c\u0438, \u0442\u043e\u0442 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 API \u0442\u044f\u0436\u0435\u043b\u043e. \u0412 Javascript API \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 (\u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u2014 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435), \u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u0430\u043a \u044d\u0442\u0438\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u0422\u0430\u043a \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <a href=\"https:\/\/github.com\/mosquito\/wsrpc\">WSRPC<\/a>. \u0414\u043b\u044f \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u044b\u0445 <a href=\"https:\/\/github.com\/mosquito\/wsrpc\">\u0432\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0434\u0435\u043c\u043e<\/a>.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u0418\u0434\u0435\u044f<\/h4>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 API \u043d\u0430 Javascript \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"javascript\">var url = window.location.protocol===&quot;https:&quot;?&quot;wss:\/\/&quot;:&quot;ws:\/\/&quot; + window.location.host + '\/ws\/'; RPC = WSRPC(url, 5000);  \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 RPC.call('test').then(function (data) {     \/\/ \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u0430\u043a *args     RPC.call('test.serverSideFunction', [1,2,3]).then(function (data) {         console.log(&quot;Server return&quot;, data)     });      \/\/ \u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b **kwargs     RPC.call('test.serverSideFunction', {size: 1, id: 2, lolwat: 3}).then(function (data) {         console.log(&quot;Server return&quot;, data)     }); });  \/\/ \u0415\u0441\u043b\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 'whoAreYou', \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \/\/ \u043e\u0442\u0432\u0435\u0442\u0438\u043c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 return RPC.addRoute('whoAreYou', function (data) {     return window.navigator.userAgent; });  RPC.connect(); <\/code><\/pre>\n<p>  \u0418 \u043d\u0430 python:  <\/p>\n<pre><code class=\"python\">import tornado.web import tornado.httpserver import tornado.ioloop import time from wsrpc import WebSocketRoute, WebSocket, wsrpc_static  class ExampleClassBasedRoute(WebSocketRoute):     def init(self, **kwargs):         return self.socket.call('whoAreYou', callback=self._handle_user_agent)      def _handle_user_agent(self, ua):         print ua      def serverSideFunction(self, *args, **kwargs):         return args, kwargs  WebSocket.ROUTES['test'] = ExampleClassBasedRoute WebSocket.ROUTES['getTime'] = lambda: time.time()  if __name__ == &quot;__main__&quot;:     http_server = tornado.httpserver.HTTPServer(tornado.web.Application((         # \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 url \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u043a\u043e\u0439 q.min.js \u0438 wsrpc.min.js         # (\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0435)         wsrpc_static(r'\/js\/(.*)'),         (r&quot;\/ws\/&quot;, WebSocket),         (r'\/(.*)', tornado.web.StaticFileHandler, {              'path': os.path.join(project_root, 'static'),              'default_filename': 'index.html'         }),     ))     http_server.listen(options.port, address=options.listen)     tornado.ioloop.IOLoop.instance().start() <\/code><\/pre>\n<h4>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>  \u041f\u043e\u044f\u0441\u043d\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h5>JavaScript<\/h5>\n<p>  \u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 RPC, \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u043e WebSocket \u0435\u0449\u0435 \u043d\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0441\u044f. \u041d\u0435 \u0431\u0435\u0434\u0430, \u0432\u044b\u0437\u043e\u0432\u044b \u0441\u0442\u0430\u043b\u0438 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0440\u0430\u0437\u0433\u0440\u0435\u0431\u0430\u0435\u043c \u043f\u0440\u0438 \u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438, \u0438\u043b\u0438 \u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u044f (promises), \u043e\u0447\u0438\u0449\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0441\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c (\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f RPC.addEventListener(\u00abonconnect\u00bb, func)). \u041d\u043e \u043f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 RPC.connect(), \u043c\u044b \u043c\u0438\u0440\u043d\u043e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u043d\u0443\u0442\u0440\u0438 RPC.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432 JSON \u043d\u0430\u0448\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0430: <\/p>\n<pre><code class=\"javascript\">{&quot;serial&quot;:3,&quot;call&quot;:&quot;test&quot;,&quot;arguments&quot;: null} <\/code><\/pre>\n<p>  \u041d\u0430 \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442: <\/p>\n<pre><code class=\"javascript\">{&quot;data&quot;: {}, &quot;serial&quot;: 3, &quot;type&quot;: &quot;callback&quot;} <\/code><\/pre>\n<p> \u0433\u0434\u0435 serial \u044d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u043a\u0430 \u043d\u0430 JS \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435 (resolve promise), \u0438 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u0437\u0430 then. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435\u2026<br \/>  \u0417\u0430\u043c\u0435\u0447\u0443 \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u043d\u0435\u0433\u043e, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<h5>Python<\/h5>\n<p>  \u041d\u0430 Python \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 WebSocket. \u0410\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 (class-property) ROUTES \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c (dict), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432, \u0438 \u043a\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0435\u0433\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0433\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u044b\u0432\u0430. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c statefull \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c.<\/p>\n<p>  \u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0447\u043a\u0443. \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f (_hidden), \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437 Javascript \u043a \u043d\u0435\u043c\u0443 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c.<\/p>\n<p>  \u0415\u0449\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u0438 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041a\u043e\u0433\u0434\u0430 \u044f \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b, \u0430 \u0431\u044b\u043b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0448\u0430\u0440\u0430\u0448\u0435\u043d. \u0423\u0432\u0438\u0434\u0435\u0442\u044c Javascript traceback \u0432 \u043f\u0438\u0442\u043e\u043d\u044f\u0447\u0438\u0445 \u043b\u043e\u0433\u0430\u0445 \u2014 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0433\u043d\u0442\u0438\u0432\u043d\u044b\u0439 \u0434\u0438\u0441\u0441\u043e\u043d\u0430\u043d\u0441. \u041d\u0443, \u0430 \u043f\u0440\u043e \u043f\u0438\u0442\u043e\u043d\u044f\u0447\u044c\u0438 Exceptions \u0432 JS \u044f \u043c\u043e\u043b\u0447\u0443.<\/p>\n<h4>\u0418\u0442\u043e\u0433<\/h4>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u0412\u0435\u0437\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430\u0434\u043e, \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0431\u0430\u0433\u0438 \u0432\u044b\u0447\u0438\u0441\u0442\u0438\u043b.<\/p>\n<h4>\u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u043c\u043e\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c \u0438 \u0434\u0440\u0443\u0437\u044a\u044f\u043c \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u043b\u0438 \u043f\u0430\u0442\u0447\u0438. \u041d\u0443, \u0438 \u0442\u0435\u0431\u0435, \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c. \u0415\u0441\u043b\u0438 \u0442\u044b \u044d\u0442\u043e \u0447\u0438\u0442\u0430\u0435\u0448\u044c, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u0443\u0445\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0442\u043e\u0433\u0434\u0430 \u0442\u0435\u0431\u0435 \u0443\u0436 \u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u044d\u0442\u0430 \u0442\u0435\u043c\u0430.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/248507\/\"> http:\/\/habrahabr.ru\/post\/248507\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/960\/20a\/2f5\/96020a2f5946495699ac1e1816cc6a6d.jpg\"\/><\/p>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 WebSocket. \u0422\u043e\u0447\u043d\u0435\u0435 \u043d\u0435 \u043e \u0441\u0430\u043c\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438, \u0430 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u042f \u0434\u0430\u0432\u043d\u043e \u0441\u043b\u0435\u0436\u0443 \u0437\u0430 \u043d\u0435\u0439. \u0415\u0449\u0435 \u043a\u043e\u0433\u0434\u0430 \u0432 2011 \u0433\u043e\u0434\u0443 \u043e\u0434\u0438\u043d \u043c\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u0433\u0430 \u043f\u0440\u0438\u0441\u043b\u0430\u043b \u043c\u043d\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <a href=\"https:\/\/tools.ietf.org\/html\/rfc6455\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442<\/a>, \u043f\u0440\u043e\u0431\u0435\u0436\u0430\u0432 \u0433\u043b\u0430\u0437\u0430\u043c\u0438, \u044f \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0441\u0441\u0442\u0440\u043e\u0438\u043b\u0441\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0443\u0442\u043e, \u0438 \u044f \u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445, \u044f \u0443\u0436\u0435 \u0431\u0443\u0434\u0443 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0430 \u0447\u0442\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043f\u0435\u043d\u0441\u0438\u044e. \u041d\u043e \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u0430\u043a, <a href=\"http:\/\/caniuse.com\/#feat=websockets\">\u0438 \u043a\u0430\u043a \u0433\u043b\u0430\u0441\u0438\u0442 caniuse.com<\/a> WebSocket \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Opera Mini (\u043d\u0430\u0434\u043e \u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u043a\u0442\u043e-\u043b\u0438\u0431\u043e \u0432\u0438\u0434\u0435\u043b Opera Mini).<\/p>\n<p>  \u041a\u0442\u043e \u0442\u0440\u043e\u0433\u0430\u043b WebSocket\u044b \u0440\u0443\u043a\u0430\u043c\u0438, \u0442\u043e\u0442 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 API \u0442\u044f\u0436\u0435\u043b\u043e. \u0412 Javascript API \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 (\u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u2014 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435), \u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u0430\u043a \u044d\u0442\u0438\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0432\u0435\u0431\u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u0422\u0430\u043a \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <a href=\"https:\/\/github.com\/mosquito\/wsrpc\">WSRPC<\/a>. \u0414\u043b\u044f \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u044b\u0445 <a href=\"https:\/\/github.com\/mosquito\/wsrpc\">\u0432\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0434\u0435\u043c\u043e<\/a>.  <\/p>\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-248507","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/248507","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=248507"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/248507\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}