@@ -66,24 +66,26 @@ public void kill() {
6666 public void run () {
6767 this .createThread = Thread .currentThread ();
6868 try {
69- if (this .asServer ) {
70- this .tcpServer = new TCPServer ();
71- this .socket = tcpServer .getSocket ();
72- } else {
73- this .tcpClient = new TCPClient ();
74- this .socket = this .tcpClient .getSocket ();
75- }
69+ if (this .asServer ) {
70+ System .out .println (
71+ "TCPChannel: note: this implementation will only accept *one* connection attempt as server" );
72+ this .tcpServer = new TCPServer ();
73+ this .socket = tcpServer .getSocket ();
74+ } else {
75+ this .tcpClient = new TCPClient ();
76+ this .socket = this .tcpClient .getSocket ();
77+ }
78+
79+ // we have got a socket
80+ if (this .listener != null ) {
81+ this .listener .channelCreated (this );
82+ }
7683 } catch (IOException ex ) {
7784 //<<<<<<<<<<<<<<<<<<debug
7885 String s = "couldn't establish connection" ;
7986 System .out .println (s );
8087 this .fatalError = true ;
8188 }
82- finally {
83- if (this .listener != null ) {
84- this .listener .channelCreated (this );
85- }
86- }
8789 }
8890
8991 public void close () throws IOException {
@@ -149,10 +151,12 @@ public OutputStream getOutputStream() throws IOException {
149151 }
150152
151153 private class TCPServer {
152- private ServerSocket srvSocket ;
154+ private ServerSocket srvSocket = null ;
153155
154156 Socket getSocket () throws IOException {
155- this .srvSocket = new ServerSocket (port );
157+ if (this .srvSocket == null ) {
158+ this .srvSocket = new ServerSocket (port );
159+ }
156160
157161 //<<<<<<<<<<<<<<<<<<debug
158162 StringBuilder b = new StringBuilder ();
0 commit comments