from chatter import BaseSocketHandler, run_application, Clients class Example1SocketHandler(BaseSocketHandler): # namespace - group = 'example1' def main(): #Tornado-handler' run_application([ (r'/example1', Example1SocketHandler), ]) if __name__ == '__main__': main()
class __api_result__(APIMethod): # , - "" def run(self, text1, text2, text3): # - tuple # - dict- # - success ( - True / False) return ({'text': [text1, text2, text3]}, True)
<!DOCTYPE html> <html> <head> <title>Chatter test</title> <meta charset="UTF-8"> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/> <!-- chatter.js --> <script src="js/vmchatter.js"></script> <script src="http://code.jquery.com/jquery.js"></script> <script> // . - function Example1Chatter(host, port, params) { // chatter', , , "" this.chatter = new VMChatter(host, port, 'example1', params, this); } // , hello Example1Chatter.prototype.hello = function(text2, text1, text3, callback) { // , , , this.chatter.applyMethod('hello', 'world', arguments); }; </script> <script type="text/javascript"> var sx; $(document).ready(function() { //, 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('<p>' + data.text + '</p>'); }); } </script> </head> <body> <button class="btn" onclick="sendHello();">Send hello</button> <div id="results"></div </body>
Source: https://habr.com/ru/post/184090/
All Articles