File tree Expand file tree Collapse file tree 3 files changed +8
-7
lines changed
Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -143,11 +143,7 @@ public void onError( Exception ex ) {
143143 ta .append ( uriField .getText () + " is not a valid WebSocket URI\n " );
144144 }
145145 } else if ( e .getSource () == close ) {
146- try {
147- cc .close ();
148- } catch ( Exception ex ) {
149- ex .printStackTrace ();
150- }
146+ cc .close ();
151147 }
152148 }
153149
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public ChatServer( InetSocketAddress address ) {
2525 @ Override
2626 public void onOpen ( WebSocket conn , ClientHandshake handshake ) {
2727 this .sendToAll ( "new connection: " + handshake .getResourceDescriptor () );
28- System .out .println ( conn + " entered the room!" );
28+ System .out .println ( conn . getRemoteSocketAddress (). getAddress (). getHostAddress () + " entered the room!" );
2929 }
3030
3131 @ Override
Original file line number Diff line number Diff line change @@ -84,7 +84,12 @@ public static void main( String[] args ) throws Exception {
8484
8585 BufferedReader reader = new BufferedReader ( new InputStreamReader ( System .in ) );
8686 while ( true ) {
87- chatclient .send ( reader .readLine () );
87+ String line = reader .readLine ();
88+ if ( line .equals ( "close" ) ) {
89+ chatclient .close ();
90+ } else {
91+ chatclient .send ( line );
92+ }
8893 }
8994
9095 }
You can’t perform that action at this time.
0 commit comments