{"id":184090,"date":"2013-06-21T09:12:04","date_gmt":"2013-06-21T05:12:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=184090"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=184090","title":{"rendered":"<span class=\"post_title\">Chatter \u2014 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 python 2.7 websocket-framework \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c tornado<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u0441\u0432\u043e\u0451 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 \u2014 Chatter.<\/p>\n<p>  Chatter \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 python 2.7, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"http:\/\/habrahabr.ru\/search\/?q=python+tornado&amp;target_type=posts\">tornado<\/a>.<\/p>\n<p>  \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u043e\u0435 API \u0434\u043b\u044f python (\u0431\u044d\u043a\u044d\u043d\u0434) \u0438 \u0434\u043b\u044f js (\u0444\u0440\u043e\u043d\u0442\u044d\u043d\u0434)<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/Vidog\/chatter\">github<\/a>.<\/p>\n<h4>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d?<\/h4>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0414\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u00ab\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u00bb \u2014 \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 json.<\/p>\n<h5>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u00abapp\u00bb \u0444\u0430\u0439\u043b\u0430:<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">from chatter import BaseSocketHandler, run_application, Clients  class Example1SocketHandler(BaseSocketHandler):     #\u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 namespace \u043f\u0440\u043e\u0435\u043a\u0442\u0430 - \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e     group = 'example1'  def main():     #Tornado-handler'\u044b     run_application([         (r'\/example1', Example1SocketHandler),     ])  if __name__ == '__main__':     main() <\/code><\/pre>\n<h5>\u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 app \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0430\u043f\u043a\u0435 <b>api<\/b>. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0430\u043f\u043a\u0438:<\/h5>\n<p>  <\/p>\n<ul>\n<li> api\/<br \/> \n<ul>\n<li> example1\/ <i>\u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442-\u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441<\/i><br \/> \n<ul>\n<li> group\/ <i>\u0433\u0440\u0443\u043f\u043f\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/i><br \/> \n<ul>\n<li> method1.py <i>\u043c\u0435\u0442\u043e\u0434 1<\/i>   <\/li>\n<li> method2.py <i>\u043c\u0435\u0442\u043e\u0434 2<\/i>   <\/li>\n<\/ul>\n<p>   <\/li>\n<\/ul>\n<p>   <\/li>\n<li> example2\/ <i>\u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 #2<\/i><br \/> \n<ul>\n<li> group\/ <i>\u0433\u0440\u0443\u043f\u043f\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/i><br \/> \n<ul>\n<li> method1.py <i>\u043c\u0435\u0442\u043e\u0434 1<\/i>   <\/li>\n<li> method2.py <i>\u043c\u0435\u0442\u043e\u0434 2<\/i>   <\/li>\n<\/ul>\n<p>   <\/li>\n<\/ul>\n<p>   <\/li>\n<\/ul>\n<p>  <\/li>\n<\/ul>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u2014 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043f\u0430\u043f\u043a\u0430 api \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u00ab\u043c\u0435\u0442\u043e\u0434\u044b\u00bb, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 (\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0433\u0438\u0442\u0435 \u2014 chat).<\/p>\n<h5>\u0424\u0430\u0439\u043b \u043c\u0435\u0442\u043e\u0434\u0430 (\/api\/example1\/hello\/world.py):<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">class __api_result__(APIMethod):         #\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 - \u0433\u043b\u0430\u0432\u043d\u043e\u0435 &quot;\u0438\u043c\u044f&quot; \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \tdef run(self, text1, text2, text3): \t\t#\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 - tuple \t\t#\u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 - dict-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \t\t#\u043f\u0435\u0440\u0432\u044b\u0439 - success (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f - True \/ False)  \t\treturn ({'text': [text1, text2, text3]}, True) <\/code><\/pre>\n<h5>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c html-js-\u0447\u0430\u0441\u0442\u044c:<\/h5>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;     &lt;title&gt;Chatter test&lt;\/title&gt;     &lt;meta charset=&quot;UTF-8&quot;&gt;     &lt;meta http-equiv=&quot;content-type&quot; content=&quot;application\/xhtml+xml; charset=utf-8&quot;\/&gt;     &lt;!-- \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c chatter.js --&gt;     &lt;script src=&quot;js\/vmchatter.js&quot;&gt;&lt;\/script&gt;      &lt;script src=&quot;http:\/\/code.jquery.com\/jquery.js&quot;&gt;&lt;\/script&gt;      &lt;script&gt;         \/\/\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b - \u0442\u0438\u043f\u043e\u0432\u044b\u0435         function Example1Chatter(host, port, params)         {             \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 chatter'\u0430, \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442, \u043f\u043e\u0440\u0442, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043d\u0443\u0436\u043d\u044b\u0439 &quot;\u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441&quot;             this.chatter = new VMChatter(host, port, 'example1', params, this);         }          \/\/\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043d\u0430\u0437\u044b\u0432\u0430\u044f \u0435\u0433\u043e hello         Example1Chatter.prototype.hello = function(text2, text1, text3, callback)         {             \/\/\u0421\u0430\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e             this.chatter.applyMethod('hello', 'world', arguments);         };     &lt;\/script&gt;      &lt;script type=&quot;text\/javascript&quot;&gt;         var sx;          $(document).ready(function()         {             \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f             sx = new Example1Chatter('localhost', 8888, {                 'onOpen': function(){                     console.log('Connected');                 },                 'onClose': function(){                     console.log('Disconnected');                 }             });         });          function sendHello()         {             sx.hello('text2', 'text1', 'text3', function(data, success)             {                 $('#results').append('&lt;p&gt;' + data.text + '&lt;\/p&gt;');             });         }     &lt;\/script&gt; &lt;\/head&gt; &lt;body&gt;             &lt;button class=&quot;btn&quot; onclick=&quot;sendHello();&quot;&gt;Send hello&lt;\/button&gt;             &lt;div id=&quot;results&quot;&gt;&lt;\/div &lt;\/body&gt; <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u043c\u0430\u0441\u0441\u043e\u0432\u0430\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0432\u0448\u0438\u043c\u0441\u044f, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443).<\/p>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043d\u043e \u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0435\u0451 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f. \u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0433\u0434\u0435 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e. \u0422\u0430\u043a \u0447\u0442\u043e \u043e\u043d \u00ab\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u00bb \u043d\u0430 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0447\u0430\u0441\u0442\u044c \u0431\u0430\u0433\u043e\u0432 \u0432\u044b\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0434\u0435\u0441\u044c \u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0433\u043e\u0442\u043e\u0432\u044f\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u00ab\u043f\u043b\u044e\u0448\u0435\u043a\u00bb.<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/Vidog\/chatter\">github<\/a>.    \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\/184090\/\"> http:\/\/habrahabr.ru\/post\/184090\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u0441\u0432\u043e\u0451 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 \u2014 Chatter.<\/p>\n<p>  Chatter \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 python 2.7, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"http:\/\/habrahabr.ru\/search\/?q=python+tornado&amp;target_type=posts\">tornado<\/a>.<\/p>\n<p>  \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u043e\u0435 API \u0434\u043b\u044f python (\u0431\u044d\u043a\u044d\u043d\u0434) \u0438 \u0434\u043b\u044f js (\u0444\u0440\u043e\u043d\u0442\u044d\u043d\u0434)<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/Vidog\/chatter\">github<\/a>.<\/p>\n<h4>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d?<\/h4>\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-184090","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184090","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=184090"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184090\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}