Socket.IO issue with control chars

I am implementing an application that uses websockets and a console accessed via Telnet. There is a communication between the connection established via websockets and the console. I am experiencing a weird issue:

  • If I send a string constant to an established socket when something is entered in the console it works ok.
  • If I send a string received from the console scope It seems to open a new socket (not sure) because in the debug log I see it and in the browser side (websockets) it alerts me of a new connection.
  • If I send a local string (instead of the one received from the other scope) it's sent correctly. (commented line: client.send(message) )

I share here the nodeJS code, take into account that this is now a test app so it's assumed only one socket and websockets connection:

// Sample based on:
// Changed for 6.x => 7.x

var events = require('events');
var eventEmitter = new events.EventEmitter();

var http = require('http');
var socketIO = require('');
var static = require('node-static');

var port = 2000;

var clientFiles = new static.Server('./client');

var httpServer = http.createServer(
    function(request, response) {
        request.addListener('end', function() { 
            clientFiles.serve(request, response);

console.log("Server running at port: " + port);

var io = require('').listen(httpServer);

var webSocket = io.sockets;

webSocket.on('connection', function(client) {
    client.send('Please enter a user name ...');
    var userName;

    eventEmitter.on('someOccurence', function(message) {
        console.log("Received: " + message);
        client.send('Line Received');
        var s = 'popo';

    client.on('message', function(message) {

        if(!userName) {
            userName = message;
            client.broadcast.send(message + ' has entered the zone.');

        var broadcastMessage = userName + ': ' + message;
        client.send("Repeated here: " + message);

    client.on('disconnect', function() {
        var broadcastMessage = userName + ' has left the zone.';

var lines = require('lines-adapter');
var net = require('net');

var server = net.createServer(function (socket) {
    socket.write("Welcome to the Server\r\n");

    lines(socket, 'utf8')
        function(line) {
            console.log("Line received: " + line);
            eventEmitter.emit('someOccurence', line);
        function() {
            console.log("End of Stream");

server.listen(1337, "");

UPDATE: I just tested with 0.8.6 and nodeJS 0.4.12 without this issue. I will keep this question here for future reference.

Fixed with v0.8.6. This q should be answered/closed.

This is just a case where you need to dynamically allocate memory locally. When the string comes in you should do a string copy of the string into a dynamically allocated string of the same length. problem solved.