Skip to content

Commit da1d539

Browse files
committed
made ExampleClient.java more expressive (TooTallNate#137)
1 parent 350bcbe commit da1d539

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/example/ExampleClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.java_websocket.drafts.Draft_10;
77
import org.java_websocket.handshake.ServerHandshake;
88

9+
/** This example demonstrates how to create a websocket connection to a server. Only the most important callbacks are overloaded. */
910
public class ExampleClient extends WebSocketClient {
1011

1112
public ExampleClient( URI serverUri , Draft draft ) {
@@ -18,22 +19,30 @@ public ExampleClient( URI serverURI ) {
1819

1920
@Override
2021
public void onOpen( ServerHandshake handshakedata ) {
22+
System.out.println( "opened connection" );
23+
// if you pan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
2124
}
2225

2326
@Override
2427
public void onMessage( String message ) {
28+
System.out.println( "received: " + message );
29+
// send( "you said: " + message );
2530
}
2631

2732
@Override
2833
public void onClose( int code, String reason, boolean remote ) {
34+
// The codecodes are documented in class org.java_websocket.framing.CloseFrame
35+
System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
2936
}
3037

3138
@Override
3239
public void onError( Exception ex ) {
40+
ex.printStackTrace();
41+
// if the error is fatal then onClose will be called additionally
3342
}
3443

3544
public static void main( String[] args ) throws URISyntaxException {
36-
ExampleClient c = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_10() );
45+
ExampleClient c = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_10() ); // more about drafts here: http://github.com/TooTallNate/Java-WebSocket/wiki/Drafts
3746
c.connect();
3847
}
3948

0 commit comments

Comments
 (0)