1
 def on_message(self, message):

     for client in ChatWebSocket.clients:
         print(client)
         t=json.loads(message)
         client.write_message(json.dumps('Content-type:application/json\n')) 
         client.write_message(json.dumps({'a':t['b']}))
         print(t['b'])

the problem is client is accepting it like a normal string and not a header please help

1 Answer 1

4

From Tornado's documentation:

WebSocketHandler.write_message(message, binary=False)

Sends the given message to the client of this Web Socket.

The message may be either a string or a dict (which will be encoded as json). If the binary argument is false, the message will be sent as utf8; in binary mode any byte string is allowed.

So you don't need to dump anything. Just send the dict as is and Tornado will encode it as JSON anyways: false, the message will be sent as utf8; in binary mode any byte string is allowed.

So you don't need to dump anything. Just send the dict as is and Tornado will

def on_message(self, message):
  for client in ChatWebSocket.clients:
    print(client)
    t = json.loads(message)
    client.write_message({'a': t['b']})
    print(t['b'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.