Node.js chatServer, clients disconnected when another user sends data

I have the following code for a node.js chatserver. The server runs and clients can telnet and connect. But when a client sends a message it auto-disconnects every other client and I don't understand what I have done wrong.

var net = require('net');
var chatServer = net.createServer();
var clientList = [];

chatServer.on('connection', function(client) {
    client.name = client.remoteAddress + ':' + client.remotePort;
    client.write("Hi " + client.name + "!\n");

    clientList.push(client);

    client.on('data', function(data) {
        broadcast(data, client);
    });

    client.on('end', function() {
        clientList.splice(clientList.indexOf(client), 1);
    });

    client.on('error', function(e) {
        console.log(e);
    });
});

function broadcast(message, client) {
    var cleanup = [];
    for(var i = 0; i < clientList.length; i++) {
        if(client !== clientList[i]) {
            if(clientList[i].writeable) {
                clientList[i].write(client.name + " says " + message);
            } else {
                cleanup.push(clientList[i]);
                clientList[i].destroy();
            }
        }
    }

    for(i = 0; i < cleanup.length; i++) {
        clientList.splice(clientList.indexOf(cleanup[i]), 1);
    }

}

chatServer.listen(9000);

You have typo here

if(clientList[i].writeable)

the correct name of that property is writable

I think the writable condition is failing for every item in the array, and hence all the clients are being deleted, as per your code. Not sure what you are trying to do with the writable check.