{"id":165791,"date":"2013-01-14T18:55:02","date_gmt":"2013-01-14T14:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=165791"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=165791","title":{"rendered":"<span class=\"post_title\">WebSocket-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Netty<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0451 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<br \/>  \u0412\u043e\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0438 \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Flash \u043d\u043e \u044f \u043d\u0435 \u0441\u0442\u0430\u043b, \u0442.\u043a. \u043c\u043e\u0451 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 i\u0414\u0435\u0432\u0430\u0439\u0441\u0430\u0445. \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0439 \u0432\u0437\u043e\u0440 \u0443\u043f\u0430\u043b \u043d\u0430 long-polling, \u043f\u0440\u043e\u0432\u0435\u0434\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432, \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0442\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0436\u0435 \u044f \u0443\u0437\u043d\u0430\u043b, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043d\u0435\u043a\u0438\u0439 WebSocket, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0440\u0435\u0448\u0438\u043b \u0431\u044b \u0432\u0441\u0435 \u043c\u043e\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041f\u043e\u0441\u0442 \u043f\u0440\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u043f\u043e\u0431\u0435\u0434\u0443 \u043d\u0430\u0434 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439.<a name=\"habracut\"><\/a><\/p>\n<h4>\u041c\u043e\u0436\u0435\u0442 \u0435\u0441\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435?<\/h4>\n<p>  \u041f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432 \u0433\u0443\u0433\u043b&#8217;\u0435, \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u043e\u0432:<br \/>  1) JWebSocket<br \/>  2) Jetty ( \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0443\u0442: <a href=\"http:\/\/habrahabr.ru\/post\/128380\/\">\u0442\u044b\u043a<\/a> )<br \/>  3) Netty<\/p>\n<p>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043e JWebSocket, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044f \u043d\u0435 \u0441\u043c\u043e\u0433 \u0441 \u043d\u0438\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f (\u0434\u0430 \u0438 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u043e\u043d, \u043d\u0435 \u0432\u0435\u0440\u044e \u044f \u0435\u043c\u0443). \u0413\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 Jetty, \u0441 \u0445\u0430\u0431\u0440\u0430, \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u043a\u0441\u0442\u0430\u0442\u0438, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u043e, \u043f\u043e \u0432\u0438\u0434\u0438\u043c\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0441 \u0447\u0435\u043c-\u0442\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u044b\/\u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u044b\/\u0443\u0434\u0430\u043b\u0435\u043d\u044b (\u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c).<br \/>  \u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e Java \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u0430\u043a\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043a\u0430\u043a js \u0438 php \u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043c\u043d\u0435 \u0434\u0430\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e. \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430, \u043d\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u043a\u043e\u0448\u0435\u043a \u0441 \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0430\u043c\u0438, \u043f\u043e\u043b\u044f\u043c\u0438 \u0438 &#8216;Hello World&#8217;, \u0430 \u0434\u043b\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e\u0433\u043e \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e.<\/p>\n<h4>\u0420\u0430\u0437 \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0443\u0434\u0435\u0442<\/h4>\n<p>  \u041d\u0435 \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0441\u0442 \u0431\u044b\u043b \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 \u043a\u043e\u0434\u0430, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043d\u0430 \u043a\u0440\u0430\u0442\u043a\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438.<br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c \u0441\u0435\u0440\u0432\u0435\u0440.  <\/p>\n<pre><code>    ExecutorService bossExec = new OrderedMemoryAwareThreadPoolExecutor(1, 400000000, 2000000000, 60, TimeUnit.SECONDS);     ExecutorService ioExec = new OrderedMemoryAwareThreadPoolExecutor(3, 400000000, 2000000000, 60, TimeUnit.SECONDS);                  ServerBootstrap networkServer = new ServerBootstrap(new NioServerSocketChannelFactory(bossExec, ioExec, 3));      networkServer.setOption(&quot;connectTimeoutMillis&quot;, 10000);     networkServer.setPipelineFactory(new WebSocketServerPipelineFactory());     Channel channel = networkServer.bind(new InetSocketAddress(address, port)); <\/code><\/pre>\n<p>  \u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Netty \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <em>Executors.newCachedThreadPool()<\/em>, \u043e\u043d \u0437\u0430\u0447\u0435\u043c-\u0442\u043e \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0436 9 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u044d\u0442\u043e \u043d\u0435\u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0440\u0430\u0442\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u0430. \u042f \u0440\u0435\u0448\u0438\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f 3\u043c\u044f \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <em>OrderedMemoryAwareThreadPoolExecutor()<\/em>.<\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0430\u043a\u0435\u0442\u044b, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f (\u0441\u043c. \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043a\u0430\u043a, \u043a\u043b\u0430\u0441\u0441 <em>WebSocketServerPipelineFactory<\/em>) \u0447\u0435\u0442\u044b\u0440\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0442\u0440\u0438 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 Netty (<em>HttpRequestDecoder<\/em>, <em>HttpChunkAggregator<\/em>, <em>HttpResponseEncoder<\/em>) \u0438 \u043e\u0434\u0438\u043d \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. <br \/>  \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <em>WebSocketServerHandler<\/em> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <em>SimpleChannelUpstreamHandler<\/em> \u0438\u0437 Netty. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <em>messageReceived<\/em> \u043f\u043e\u0434 \u043d\u0443\u0436\u0434\u044b, \u0430 \u043d\u0443\u0436\u0434\u044b \u0442\u0430\u043a\u043e\u0432\u044b:<br \/>  1) \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 http:\/\/<br \/>  2) \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 ws:\/\/<\/p>\n<p>  \u0414\u043b\u044f \u0441\u0435\u0433\u043e \u043f\u0438\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<pre><code>    if (msg instanceof HttpRequest) {         handleHttpRequest(ctx, (HttpRequest) msg);     }else if (msg instanceof WebSocketFrame) {         handleWebSocketFrame(ctx, (WebSocketFrame) msg);     } <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 <em>handleHttpRequest<\/em> \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 websocket \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 GET, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0445 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u043f\u043e http, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &quot;<em>505 HTTP Version Not Supported<\/em>&quot;.  <\/p>\n<pre><code>    sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, HTTP_VERSION_NOT_SUPPORTED)); <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 ws \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code>    if(req.getMethod() == GET && req.getUri().equals(WEBSOCKET_PATH) && Values.UPGRADE.equalsIgnoreCase(req.getHeader(CONNECTION)) && WEBSOCKET.equalsIgnoreCase(req.getHeader(Names.UPGRADE))) {         WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, false);         handshaker = wsFactory.newHandshaker(req);                      if(handshaker == null){             wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.getChannel());         }else{             handshaker.handshake(ctx.getChannel(), req).addListener(WebSocketServerHandshaker.HANDSHAKE_LISTENER);         }         return;     }     \/\/\u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 HTTP_VERSION_NO.... <\/code><\/pre>\n<p>  \u041e\u0431\u0443\u0441\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0442\u0435\u043c, \u0447\u0442\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c GET \u043d\u0430 \u043d\u0430\u0448 WEBSOCKET_PATH \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Upgrade: websocket. \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f (handshake), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0432\u0435\u0440\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0441 http \u043d\u0430 ws \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435.<br \/>  \u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434 <em>handleWebSocketFrame<\/em> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u043e \u043b\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u043f\u0430\u043a\u0435\u0442 ping \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043b\u0438 \u043f\u0440\u0438\u0448\u0435\u043b, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0438\u043d\u044f\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430\u0437\u0430\u0434 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<br \/>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u0438\u0441\u043b\u0430\u043b \u043a\u043b\u0438\u0435\u043d\u0442:  <\/p>\n<pre><code>    String clietnMsg = ((TextWebSocketFrame) frame).getText(); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u043d\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430.  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u042d\u0442\u043e \u0431\u044b\u043b\u0430 \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u043b\u0438\u0447\u043d\u0430\u044f \u043f\u043e\u0431\u0435\u0434\u0430 \u043d\u0430\u0434 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0445\u043e\u0442\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Netty, \u043a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e \u044f \u0442\u0430\u043a \u0436\u0435 \u0447\u0438\u0442\u0430\u043b \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0445\u0430\u0431\u0440).<br \/>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043b\u044e\u0431\u043e\u0439 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 WebSocket \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Netty.<\/p>\n<h4>\u041f\u043e\u0441\u0442\u0441\u043a\u0440\u0438\u043f\u0442\u0443\u043c<\/h4>\n<p>  \u0423 \u043c\u0435\u043d\u044f \u0435\u0449\u0435 \u043d\u0435\u0442 \u0440\u0435\u043f\u043e\u0440\u0435\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0432 git, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e \u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435 <a href=\"http:\/\/p.dev.aengine.ru\/src.zip\">\u0441 \u043c\u043e\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/a>, <a href=\"http:\/\/narod.ru\/disk\/65454456001.4d1bb80b8dd1cea7aae6590be5489d6e\/src.zip.html\">\u0437\u0435\u0440\u043a\u0430\u043b\u043e \u043d\u0430 \u041d\u0430\u0440\u043e\u0434\u0435<\/a><\/p>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u043e \u0442\u0435\u043c\u0435:<br \/>   \u2014 <a href=\"http:\/\/habrahabr.ru\/post\/149122\/\">\u0421\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 python \u0434\u043b\u044f websockets<\/a><br \/>   \u2014 <a href=\"http:\/\/habrahabr.ru\/post\/124089\/\">\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0440\u0435\u0432\u0435\u0440\u0441-\u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Web Sockets \u0432 Nginx<\/a><br \/>   \u2014 <a href=\"http:\/\/habrahabr.ru\/post\/80466\/\">\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445<\/a> \t\t\t \t\t\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\/165791\/\"> http:\/\/habrahabr.ru\/post\/165791\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0451 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<br \/>  \u0412\u043e\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0438 \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Flash \u043d\u043e \u044f \u043d\u0435 \u0441\u0442\u0430\u043b, \u0442.\u043a. \u043c\u043e\u0451 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 i\u0414\u0435\u0432\u0430\u0439\u0441\u0430\u0445. \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0439 \u0432\u0437\u043e\u0440 \u0443\u043f\u0430\u043b \u043d\u0430 long-polling, \u043f\u0440\u043e\u0432\u0435\u0434\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432, \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0442\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0436\u0435 \u044f \u0443\u0437\u043d\u0430\u043b, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043d\u0435\u043a\u0438\u0439 WebSocket, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0440\u0435\u0448\u0438\u043b \u0431\u044b \u0432\u0441\u0435 \u043c\u043e\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041f\u043e\u0441\u0442 \u043f\u0440\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u043f\u043e\u0431\u0435\u0434\u0443 \u043d\u0430\u0434 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439.<\/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-165791","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/165791","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=165791"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/165791\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}