It infuriates me. I am using Tornado 3.2 with python 2.7. I tried this both on my test computer (Windows) and on my Linux box. I am just testing the waters with (as I thought) a dead simple chat application. Here is the code so far:
class LobbyWS(tornado.websocket.WebSocketHandler):
clients = []
def open(self, *args):
self.stream.set_nodelay(True)
self.ping('one')
LobbyWS.clients.append(self)
print 'opening %s' % self
def on_pong(self, data):
print 'got pong', data
def on_message(self, message):
print "Client %s received a message : %s" % (self, message)
for client in LobbyWS.clients:
client.write_message(message)
def on_close(self):
print "Client %s closed." % self
LobbyWS.clients.remove(self)
The code seems to be working fine. However, if I remove self.ping (), it will stop working. The socket opens at the end of the browser, however, the on_message () function on the server is never called (the same behavior in Chrome and Firefox). Why does it seem that the server should send data to the socket before it can receive it?
source
share