File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,13 +23,7 @@ broadCastStream.write = function (data) {
2323 continue ;
2424 }
2525
26- var socket = peers [ p ] ;
27-
28- if ( socket . writable ) {
29- socket . write ( data ) ;
30- } else {
31- delete peers [ p ] ;
32- }
26+ peers [ p ] . write ( data ) ;
3327 }
3428 }
3529} ;
@@ -38,6 +32,9 @@ var commands = {
3832 'data' : function ( ) {
3933 console . log ( dataStore ) ;
4034 } ,
35+ 'me' : function ( ) {
36+ console . log ( myPort ) ;
37+ } ,
4138 'events' : function ( ) {
4239 console . log ( Object . keys ( events ) ) ;
4340 } ,
@@ -80,8 +77,12 @@ var connect = function (others) {
8077
8178 connect ( result . peers ) ;
8279
83- socket . pipe ( broadCastStream ) ;
80+ socket . pipe ( broadCastStream , { end : false } ) ;
8481 } ) ;
82+
83+ socket . on ( 'close' , function ( ) {
84+ console . log ( o + ' closed' )
85+ } ) ;
8586
8687 socket . on ( 'end' , function ( ) {
8788 console . log ( o + ' ended' ) ;
@@ -97,12 +98,11 @@ var server = net.createServer(function (socket) {
9798
9899 socket . once ( 'data' , function ( data ) {
99100 var result = JSON . parse ( data ) ;
100-
101101 port = result . port ;
102102 peers [ port ] = socket ;
103-
104103 connect ( result . peers ) ;
105- socket . pipe ( broadCastStream ) ;
104+
105+ socket . pipe ( broadCastStream , { end : false } ) ;
106106 } ) ;
107107
108108 socket . on ( 'end' , function ( ) {
You can’t perform that action at this time.
0 commit comments