sock.onopen = function () {
     if (typeof cb === 'function') cb();
     ready = true;
     buffer.forEach(function (msg) {
         sock.send(msg);
     });
     buffer = [];
     stream.emit('connect')
     if (stream._ended) stream.end();
 };
 sock.onclose = function () {
     stream.emit('end');
     stream.writable = false;
     stream.readable = false;
 };
 sock.onmessage = function (e) {
     stream.emit('data', e.data);
 };