@@ -73,8 +73,13 @@ public void notifyPeerConnected(CharSequence targetPeerID, StreamPair streamPair
7373 System .out .println (peerID + " writes pure bytes: " + this .messageA );
7474 streamPair .getOutputStream ().write (testBytes );
7575 byte [] receivedBytes = new byte [10 ];
76- System .out .println (peerID + " available: " + streamPair .getInputStream ().available ());
77- //Thread.sleep(100); // give other process a moment
76+ int available = streamPair .getInputStream ().available ();
77+ if (available < 1 ) {
78+ //System.out.println(peerID + " try to go in read block");
79+ System .out .println (peerID + " sleep" );
80+ //streamPair.getInputStream().read();
81+ Thread .sleep (100 ); // give other process a moment
82+ }
7883 System .out .println (peerID + " available #2: " + streamPair .getInputStream ().available ());
7984 streamPair .getInputStream ().read (receivedBytes );
8085 System .out .println (peerID + " available #3: " + streamPair .getInputStream ().available ());
@@ -89,12 +94,15 @@ public void notifyPeerConnected(CharSequence targetPeerID, StreamPair streamPair
8994 byte [] outBytes = baos .toByteArray ();
9095 ASAPSerialization .writeByteArray (outBytes , streamPair .getOutputStream ());
9196
97+ System .out .println (peerID + " sleep - other threads need to get a chance. Is that still a bug? " );
98+ Thread .sleep (100 ); // give other process a moment
99+
92100 // read
93101 System .out .println (peerID + " reading.." );
94102 if (PeerIDHelper .sameID (peerID , ALICE_ID )) {
95103 int i = 42 ; // debug break
96104 }
97- Thread .sleep (1000 );
105+ // Thread.sleep(1000);
98106 byte [] inBytes = ASAPSerialization .readByteArray (streamPair .getInputStream ());
99107 ByteArrayInputStream bais = new ByteArrayInputStream (inBytes );
100108 String receivedMessage = ASAPSerialization .readCharSequenceParameter (bais );
@@ -118,6 +126,9 @@ public void notifyPeerConnected(CharSequence targetPeerID, StreamPair streamPair
118126 outBytes = baos .toByteArray ();
119127 ASAPSerialization .writeByteArray (outBytes , streamPair .getOutputStream ());
120128
129+ System .out .println (peerID + " sleep - other threads need to get a chance. Is that still a bug? " );
130+ Thread .sleep (100 ); // give other process a moment
131+
121132 System .out .println (this .peerID + " reading.. " );
122133 inBytes = ASAPSerialization .readByteArray (streamPair .getInputStream ());
123134 bais = new ByteArrayInputStream (inBytes );
0 commit comments