SyntaxError: Unexpected end of input (nodejs tcp server)-Collection of common programming errors
You could wait for emitting end event, and then parse it.
Example:
// Handle incoming messages from clients.
data = '';
socket.on('data', function (chunk) {
data += chunk;
});
// Handle incoming messages from clients.
socket.on('end', function () {
var obj = JSON.parse(data);
if(obj.type == "register") {
_clientObj[obj.msg] = {
client: 'Client',
socketID: socket.name
}
console.log("Register...");
} else if(obj.type == "message") {
console.log(socket.name + " --> message: " + obj.msg);
}
});
Documentation: http://nodejs.org/api/all.html#all_event_end_1