[英]socket.io not able to pass array threw emit
I've been working on some type of game where I have to pass a map which is available as an Array to the players. 我一直在从事某种类型的游戏,在这种游戏中,我必须将作为数组可用的地图传递给玩家。 I already looked at other posts who suggested to pass the array as an object but this produces the following problem: 1. The user doesn't receive the object or the array 2. I got a script that logs whenever a client (dis)connects and it's showing me that a client always connects and disconnects. 我已经看过其他建议将数组作为对象传递的帖子,但这会产生以下问题:1.用户没有收到对象或数组2.我得到了一个脚本,该脚本在客户端断开连接时记录它向我展示了客户端始终会连接和断开连接。 (Probably the client times out and tries to reconnect??) (可能客户端超时并尝试重新连接?)
The server code looks like this: 服务器代码如下所示:
io.sockets.on('connection', onConnect);
function onConnect(socket) {
console.log("We have a new client: " + socket.id);
socket.emit('field', {fields});
socket.on('disconnect', function() {
console.log("Client " + socket.id + " has disconnected!");
});
}
And the client code: 和客户端代码:
socket = io.connect('http://localhost:3000');
socket.on("field",
function(data) {
console.log(data);
}
);
I'm able to pass a single object of the array, but not the whole one... 我可以传递数组的单个对象,但不能传递整个对象...
Edit: The code itself works with a string but not with an array that I want to be passed... 编辑:代码本身使用字符串,但不适用于我要传递的数组...
I found out that socket.io is not able to emit large arrays (highest array length was a bit less than 8000 (the array was filled with objects that contain 2 properties)). 我发现socket.io无法发出大型数组(最长的数组长度小于8000(数组中填充了包含2个属性的对象))。 Probably this is some type of storage error (could be user specific)... 可能这是某种类型的存储错误(可能是用户特定的)...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.