22
33//import net.sharksystem.asap.ASAPEncounterHelper;
44
5+ import net .sharksystem .utils .Log ;
56import net .sharksystem .utils .streams .StreamPairImpl ;
67
78import java .io .IOException ;
1314
1415public class SocketFactory implements Runnable {
1516 private final ServerSocket srv ;
17+ private int port = 0 ;
1618 private StreamPairCreatedListener listener = null ;
1719 InputStream is ;
1820 OutputStream os ;
@@ -21,24 +23,33 @@ public class SocketFactory implements Runnable {
2123
2224 public SocketFactory (int portNumber , StreamPairCreatedListener listener ) throws IOException {
2325 this (new ServerSocket (portNumber ));
26+ this .port = portNumber ;
2427 this .listener = listener ;
2528 }
2629
2730 public SocketFactory (ServerSocket srv ) {
2831 this .srv = srv ;
2932 }
3033
34+ /**
35+ * Close server socket - kills thread already running
36+ */
37+ public void close () throws IOException {
38+ Log .writeLog (this , "close TCP server socket - do long longer accept connection attempts on port: " + this .port );
39+ this .srv .close ();
40+ }
41+
3142 private boolean running = false ;
3243 @ Override
3344 public void run () {
3445 this .running = true ;
35- System . out . println ( "socket factory running" );
46+ Log . writeLog ( this , "socket factory running - accept connections on port: " + this . port );
3647 try {
3748 Socket socket = srv .accept ();
3849 this .is = socket .getInputStream ();
3950 this .os = socket .getOutputStream ();
4051 this .remoteAddress = SocketFactory .getRemoteAddress (socket );
41- System . out . println ( " socket created" );
52+ Log . writeLog ( this , "connection attempt accepted: socket created" );
4253 if (this .waitForConnectionThread != null ) {
4354 //this.waitForConnectionThread.interrupt();
4455 this .waitForConnectionThread .notify ();
0 commit comments