var fs = require('fs');
var io = require('socket.io-client');
var ss = require('socket.io-stream');

var SERVER_URL = process.env.SERVER_URL || 'http://local.host:3000';
var socket = io(SERVER_URL + '/stream', { query: "type=client" });

socket.on('connect_error', function(){
	console.log('Connection Failed');
});
socket.on('disconnect', function () {
	console.log('Disconnected');
});
socket.on('connect', function(){
	console.log('Connected');
	var stream = ss.createStream();

	var imgs = ['test1.jpg', 'test2.jpg'];
	var i = 0;

	// emit image stream
	function emitImage() {
		console.log('client:emitImage ' + imgs[i]);
		i = i^1;
		var stream = ss.createStream();
		fs.createReadStream(imgs[i]).pipe(stream);
		ss(socket).emit('client:emitImage', stream, { name: imgs[i] });
	}

	emitImage();
	var interval = setInterval(emitImage, 1000);
});

@@ -21,46 +21,8 @@
 ');%0A
-var io = require('socket.io-client');%0A
 var 
@@ -138,18 +138,43 @@
 ocket = 
-io
+require('socket.io-client')
 (SERVER_
@@ -191,17 +191,19 @@
 ream', %7B
- 
+%0A%09%09
 query: %22
@@ -214,17 +214,46 @@
 =client%22
- 
+,%0A%09%09transports: %5B'websocket'%5D%0A
 %7D);%0A%0Asoc
@@ -451,24 +451,25 @@
 g('Connected
+.
 ');%0A%09var str
@@ -569,16 +569,51 @@
  stream%0A
+%09console.log('start emitting...');%0A
 %09functio
@@ -630,16 +630,19 @@
 e() %7B%0A%09%09
+// 
 console.

use websocket