Skip to content Skip to sidebar Skip to footer

Could Not Decode A Text Frame As Utf-8.

Now i have struggled to get this bug fixed, but i cannot find out how to fix it, i have searched and found a solution, but it wasn't exactly a solution for the problem. It's everyt

Solution 1:

That sounds like a bug in the PHP WebSocket server that you are using. It indicates that server has not properly constructed the WebSocket frame properly and it contains non-UTF8 data or the server split a message into two frames and the UTF-8 data got split in the middle of a multi-byte character encoding.

Also, you shouldn't need to escape(encodeURIComponent(STRING)). The result of JSON.stringify should already be safe to send as a WebSocket message.

Solution 2:

It's a old subject, but in case people do search for similar bug I put an answer here.

Recently I encoutered problem with a php websocket server, the javascript client in chrome close the connection saying "could not decode a text frame as UTF8".

I searched the net in order to found a answer, and trying different response saying about replacing bad utf8 character, or using encodeURI or using unescape etc...

But after reading a part of the websocket specs, I checked the frame send on the php server. I see that for frame length under 126 bytes long it was working great, but for frame longer than 126 bytes, it's generate an error on the client side. After a little frame inspection I see that the length of the frame was stored in little endian order, or based on an example in the specs the frame length need to be in big endian order.

So after putting the right endian order for the length everything goes fine.

Post a Comment for "Could Not Decode A Text Frame As Utf-8."