Note that there are some explanatory texts on larger screens.

plurals
  1. POWebSocket Server sending messages periodically in python
    primarykey
    data
    text
    <p>I have a tornado web server in python:</p> <pre><code>import tornado.httpserver import tornado.websocket import tornado.ioloop from tornado.ioloop import IOLoop import tornado.web import time import threading import sys from datetime import datetime from datetime import timedelta def sample(): print 'hiiiii' threading.Timer(10, sample).start() class WSHandler(tornado.websocket.WebSocketHandler): def open(self): print 'new connection' def on_message(self, message): self.write_message(message) self.msg('hellooooooo') print message def msg(self,message): self.write_message(message) threading.Timer(10, self.msg('in timer')).start() print 'in msg'+message def on_close(self): print 'connection closed' application = tornado.web.Application([ (r'/', WSHandler), ]) if __name__ == "__main__": http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8888) interval_ms=120 main_loop=tornado.ioloop.IOLoop.instance() main_loop.start() </code></pre> <p>And the client is </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; function fun(){ alert("in fun()"); var val=document.getElementById("txt"); var ws = new WebSocket("ws://localhost:8888"); ws.onopen = function(evt) { alert("Connection open ..."); ws.send(val.value); }; ws.onmessage = function(evt) { alert("from server: "+evt.data); } ws.onclose = function(evt) { alert("Connection closed."); } } &lt;/script&gt; &lt;/head&gt; &lt;body bgcolor="#FFFFFF"&gt; &lt;input type="text" id="txt" /&gt; &lt;button onClick="fun()"&gt;click&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I want to get the message periodically to the client. But when I try this I get this error: <code>RunTimeError :Maximum Recursion Depth Exceeded.</code> Please help me solve this issue. Also, how do we know what are the clients connected to the server?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload