File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,30 +64,25 @@ var connect = function (others) {
6464 return ;
6565 }
6666
67- var socket = net . connect ( o , function ( err ) {
68- peers [ o ] = socket ;
69- } ) ;
67+ var socket = peers [ o ] = net . connect ( o ) ;
7068
7169 socket . once ( 'data' , function ( data ) {
7270 var result = JSON . parse ( data ) ;
73-
7471 socket . write ( JSON . stringify ( { port : myPort , peers : Object . keys ( peers ) } ) ) ;
75-
7672 dataStore = result . data ;
77-
7873 connect ( result . peers ) ;
79-
8074 socket . pipe ( broadCastStream , { end : false } ) ;
8175 } ) ;
82-
83- socket . on ( 'close' , function ( ) {
84- console . log ( o + ' closed' )
85- } ) ;
8676
87- socket . on ( 'end' , function ( ) {
88- console . log ( o + ' ended' ) ;
77+ function cleanup ( ) {
8978 delete peers [ o ] ;
90- } ) ;
79+
80+ socket . removeListener ( 'error' , cleanup ) ;
81+ socket . removeListener ( 'end' , cleanup ) ;
82+ }
83+
84+ socket . on ( 'error' , cleanup ) ;
85+ socket . on ( 'end' , cleanup ) ;
9186 } ) ;
9287} ;
9388
You can’t perform that action at this time.
0 commit comments