11package howto ;
22
3- import net .sharksystem .asap .ASAPConnectionHandler ;
4- import net .sharksystem .asap .ASAPException ;
5- import net .sharksystem .asap .ASAPPeer ;
6- import net .sharksystem .asap .ASAPPeerFS ;
7- import net .sharksystem .utils .streams .StreamPair ;
8- import net .sharksystem .utils .streams .StreamPairImpl ;
3+ import net .sharksystem .asap .*;
94import net .sharksystem .utils .tcp .SocketFactory ;
105import net .sharksystem .utils .testsupport .TestConstants ;
116import net .sharksystem .utils .testsupport .TestHelper ;
@@ -33,8 +28,14 @@ public class ConnectPeers {
3328
3429 private static final String TEST_FOLDER = "ConnectPeers" ;
3530 private CharSequence EXAMPLE_APP_FORMAT = "shark/x-connectPeersExample" ;
36- private int PORT_NUMBER = 7777 ;
3731
32+ /**
33+ * A single connection is set up and two peers run an ASAP encounter. It can work in test scenarios. It is not
34+ * a blueprint for a real application though - better use our encounter manager.
35+ * @throws IOException
36+ * @throws ASAPException
37+ * @throws InterruptedException
38+ */
3839 @ Test
3940 public void connectAliceAndBob () throws IOException , ASAPException , InterruptedException {
4041 // supported formats
@@ -61,7 +62,10 @@ public void connectAliceAndBob() throws IOException, ASAPException, InterruptedE
6162 https://github.com/SharedKnowledge/ASAPJava/blob/master/src/main/java/net/sharksystem/asap/apps/testsupport/ASAPTestPeerFS.java
6263 */
6364
64- ServerSocket serverSocket = new ServerSocket (PORT_NUMBER );
65+ // get a port number for that test
66+ int portNumber = TestHelper .getPortNumber ();
67+
68+ ServerSocket serverSocket = new ServerSocket (portNumber );
6569
6670 /*
6771 now. We need to accept incoming connection but have to create a socket at the same time...
@@ -73,7 +77,7 @@ public void connectAliceAndBob() throws IOException, ASAPException, InterruptedE
7377
7478 // create a socket
7579 String addressRemotePeer = "localhost" ; // change this in a real scenario
76- Socket socket = new Socket (addressRemotePeer , PORT_NUMBER );
80+ Socket socket = new Socket (addressRemotePeer , portNumber );
7781
7882 // give server side a moment to connect
7983 Thread .sleep (1 );
@@ -84,6 +88,5 @@ public void connectAliceAndBob() throws IOException, ASAPException, InterruptedE
8488
8589 // give it some time to run an encounter.
8690 Thread .sleep (5 );
87-
8891 }
8992}
0 commit comments