Have an app that is using (Python 3.6) Tkinter & Tornado. Would like it send a websocket message when a button is pressed.
The sendSocket is in my class that handles the interface. I am able to open my sockets ok, and can send data into the socket handler ok. Additionally, it serves up my html file ok from my RequestHandler.
I can see that my code hits the sendSocketMessage line ok. However, I never get the print from within the SocketHandler.send_message def. There are no errors in the console.
def sendSocketMessage(self, data = "whatever"):
print("sending")
#WebSocketeer.send_message(data)
ioloop.IOLoop.current().add_callback(WebSocketeer.send_message, data)
class WebSocketeer(websocket.WebSocketHandler):
def open(self):
print("WebSocket opened")
def on_message(self, message):
print("got message: " + message)
def on_close(self):
print("WebSocket closed")
@classmethod
def send_message(self, message):
print("sending message: " + message)
for session_id, session in self.session.server._sessions._items.iteritems():
session.conn.emit(event, message)
Code based off of these SO responses
Send a websocket message: How do I send a websocket message in Tornado at will?
Send to all clients: Is it possible to send a message to all active WebSocket connections? Using either node.js or python tornado websockets