Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Last active December 23, 2015 10:29
Show Gist options
  • Save jonathanmarvens/6621449 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/6621449 to your computer and use it in GitHub Desktop.
( function () {
var
net,
sockets
;
net = this.require( "net" );
sockets = [];
net
.createServer( function ( socket ) {
sockets.push( socket );
socket.on( "data", function ( data ) {
for (
var
a = 0,
b = sockets.length
; a < b; a++
) {
if ( sockets[ a ] !== socket ) {
sockets[ a ].write( data );
}
}
} );
socket.on( "end", function () {
var
socket_index
;
socket_index = sockets.indexOf( socket );
sockets.splice( socket_index, 1 );
} );
} )
.listen( 8000 )
;
} ).call( this );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment