客户端websocket限制消息长度 [英] client side websocket restricting message length

查看:1531
本文介绍了客户端websocket限制消息长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js开发一个websockter服务器,我在Chrome中发现了一些怪癖。 Chrome on(OS X 10.7 64位)最大字符串长度为17740,而Firefox似乎处理非常大的字符串没有问题。我发现的另一个问题是可以在websocket hybi-17中发送的最大消息长度是2 ^ 64-1,或者是无符号64位整数中的max int,但是javascript甚至无法处理数字格式大的数字。让你的协议使用你的前端语言无法轻易处理的数字似乎很奇怪。所以这里真正的问题是有一种方法可以强制浏览器中的websocket接口将消息限制到一定的长度。我可以轻松地使用自己的函数来完成它,但我知道真正信任任何客户端代码都是不好的。我正在寻找在所有平台上获得一致性的最佳方法。

I'm developing a websockter server using node.js and I've discovered some quirks in Chrome. Chrome on (OS X 10.7 64 bit) the max string length is 17740, whereas Firefox seems to handle the very large string with no problem. Another problem I found is that the max message length that can be sent in websocket hybi-17 is 2^64-1, or max int in an unsigned 64 bit integer, but javascript can't even handle numbers that large in its number format. It seems odd to have your protocol use numbers that your front end language can't handle easily. So the real question here is there a way I can force the websocket interface in the browser to restrict messages to a certain length. I can easily do it with my own functions, but I know its bad to really trust any client side code. I'm looking for the best way to get some consistency across all platforms.

推荐答案

如果传入的话,将其限制在服务器上数据太长,只需关闭连接。

Restrict it on the server, if the incoming data is too long, just close the connection.

这篇关于客户端websocket限制消息长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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