Node JS UDP服务器:偏移到缓冲区太大(错误)

时间:2016-06-17 12:18:42

标签: node.js server udp

我正在尝试通过以下方式向客户发送消息:

server.send(new Buffer("Hello World!"), data.port, data.ip);

但我总是收到以下错误:

dgram.js:256
throw new RangeError('Offset into buffer too large');
      ^
RangeError: Offset into buffer too large
at Socket.send (dgram.js:256:11)
at Socket.<anonymous> (/home/lchost/fishy.io/server/custom_modules/game.js:50:14)
at Socket.emit (events.js:98:17)
at UDP.onMessage (dgram.js:441:8)

任何想法我做错了什么?

2 个答案:

答案 0 :(得分:0)

我应该这样做:

server.send(new Buffer("Hello World!"), 0, 0, data.port, data.ip);

答案 1 :(得分:0)

var data = new Buffer("Hello World!");

server.send(data, 0, data.length, data.port, data.ip);

在节点 v0.10.29 中测试