【发布时间】:2014-06-28 14:27:00
【问题描述】:
我在服务器上有这个:
io.sockets.on('connection', function (client) {
client.on('message', function (message) {
try {
var incomingJSON = JSON.parse(message);
console.log("Message received");
console.log(incomingJSON.message);
console.log(incomingJSON.coordinates);
} catch (e) {
console.log(e);
client.disconnect();
}
});
});
这在客户端:
var socket = io.connect('http://localhost:8008');
$("#ready").click(function(){
socket.emit("message", {message: "ready", coordinates: "21"});
});
我在 node.js 控制台而不是我的消息上得到了这个:
[SyntaxError: Unexpected token o]
info: booting client
info: transport end by forced client disconnection
debug: websocket writing 0::
info: transport end (booted)
请帮我将我的 JSON 从客户端发送到服务器,并告诉我我做错了什么。
【问题讨论】:
标签: javascript json node.js sockets socket.io