Skip to content

Commit dde2740

Browse files
committed
the ChatServer can now be used to send messages via System.in
enabled debug mode by default for example projects
1 parent 2ca6d17 commit dde2740

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎example/ChatServer.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import java.io.BufferedReader;
12
import java.io.IOException;
3+
import java.io.InputStreamReader;
24

35
import net.tootallnate.websocket.WebSocket;
46
import net.tootallnate.websocket.WebSocketServer;
@@ -43,13 +45,20 @@ public void onError(Throwable ex) {
4345
ex.printStackTrace();
4446
}
4547

46-
public static void main(String[] args) {
48+
public static void main(String[] args) throws IOException {
49+
WebSocket.DEBUG = true;
4750
int port = 8887;
4851
try {
4952
port = Integer.parseInt(args[0]);
5053
} catch(Exception ex) {}
5154
ChatServer s = new ChatServer(port);
5255
s.start();
5356
System.out.println("ChatServer started on port: " + s.getPort());
57+
58+
BufferedReader sysin = new BufferedReader( new InputStreamReader( System.in ) );
59+
while(true){
60+
String in = sysin.readLine();
61+
s.sendToAll( in );
62+
}
5463
}
5564
}

‎src/net/tootallnate/websocket/WebSocket.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public enum Role{
6161
*/
6262
public static final byte END_OF_FRAME = (byte)0xFF;
6363

64-
public static final boolean DEBUG = false;
64+
public static /*final*/ boolean DEBUG = false; //must be final in the future in order to take advantage of VM optimization
6565

6666

6767
// INSTANCE PROPERTIES /////////////////////////////////////////////////////
@@ -415,5 +415,9 @@ private void open(){
415415
public int getPort(){
416416
return socketChannel.socket().getLocalPort();
417417
}
418-
418+
419+
@Override
420+
public String toString( ) {
421+
return super.toString(); //its nice to be able to set breakpoints here
422+
}
419423
}

0 commit comments

Comments
 (0)