Here https://developer.mozilla.org/en/WebSockets/WebSockets_reference/MessageEvent it states attribute data is of type DOMString| Blob | ArrayBuffer. How do I tell it which type I want? Or how do I know which type I get?
The WebSocket. onmessage property is an event handler that is called when a message is received from the server. It is called with a MessageEvent .
The only way to know the client received the webSocket message for sure is to have the client send your own custom message back to the server to indicate you received it and for you to wait for that message on the server. That's the ONLY end-to-end test that is guaranteed.
First, you need to copy your web browser's header to here and use json. dumps to convert it into the string format. After that, create the connection to the server by using create_connection . Then, perform the handshake by sending the message, and you will be able to see the data on your side.
The best method is to parse using third party library like jQuery. In both XML and JSON, the server responds as a string, which is being parsed at the client end.
The appropriate two types of frames that a server can send are text frames and binary frames (5.2). The ws.binaryType allows you to define in which format you'd like to obtain the binary data.
binaryType being set to either arraybuffer or blob To determine the type, you can use:
e.data instanceof ArrayBuffere.data instanceof Blobtypeof e.data === "string"Reference:
4. If type indicates that the data is Text, then initialize event's
dataattribute to data.If type indicates that the data is Binary, and
binaryTypeis set to "blob", then initialize event'sdataattribute to a newBlobobject that represents data as its raw data.If type indicates that the data is Binary, and
binaryTypeis set to "arraybuffer", then initialize event'sdataattribute to a new read-onlyArrayBufferobject whose contents aredata.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With