无法将文本框架解码为 UTF-8. [英] Could not decode a text frame as UTF-8.

查看:29
本文介绍了无法将文本框架解码为 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.

每次我在聊天应用程序中进入房间"时,我都会因无法将文本框架解码为 UTF-8"而断开连接.

It's everytime i "entering a room" in my chat-application i am getting disconnected with "Could not decode a text frame as UTF-8.".

  • 我将所有命令发送到 WebSocket 服务器(在 PHP 中作为 json)

我通过 WebSocket (ws://....) 发送的命令是:

The command i send though WebSocket (ws://....) is:

  {"command": "roomchange", "data" : "14"}

我的 php websocket 服务器处理请求并发回导致问题的 thid:

My php websocket server handle the requist and send back thid which cause the problem:

{"command" : "NEWUSER","data" : { "mood" : "tired", "apartment" : "0","username" : "tester","seat_id" : "7","room_id" : "14","gender" : "male", "face" : "", "hair" : "http://xxx.dk/framework/gfxs/avatars/male/hair/d0fc74a351b05cae75258e93422c040e.png", "shoes" : "http://xxx.dk/framework/gfxs/avatars/male/shoes/00708715be7e7c007fca457eb5573637.png", "clothes" : "http://xxx.dk/framework/gfxs/avatars/male/shirts/9401f96ed9d6ad43c5d5ad7352e50de2.png"}}

也许是这样:

  {"command": "roombg","data" : { "id" : "14", "background" : "new.png", "name" : "Diskotek"}}

当我用php向我的websocket服务器发送请求时,我有这个

When i send request to my websocket server in php i have this to

return unescape( encodeURIComponent( JSON.stringify( COMMAND ) ) )

是否导致 websockets 发回 URL?或者是什么问题?

Is it cause the websockets send back the URL's? Or what is the problem?

推荐答案

这是一个古老的主题,但如果人们确实搜索了类似的错误,我会在此处提供答案.

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

最近我遇到了 php websocket 服务器的问题,chrome 中的 javascript 客户端关闭了连接,说无法将文本框架解码为 UTF8".

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".

我在网上搜索以找到答案,并尝试了不同的回答,说替换坏的 utf8 字符,或使用 encodeURI 或使用 unescape 等...

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...

但是在阅读了一部分 websocket 规范后,我检查了 php 服务器上发送的帧.我看到对于 126 字节以下的帧长度,它运行良好,但对于超过 126 字节的帧,它会在客户端生成错误.经过一些帧检查后,我发现帧的长度是以小端顺序存储的,或者根据规范中的示例,帧长度需要以大端顺序存储.

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.

这篇关于无法将文本框架解码为 UTF-8.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆