Skip to content

Commit 5b47329

Browse files
committed
Added callback for successfull start of server
onStart is going to get called when server is successfully started
1 parent 7e97e02 commit 5b47329

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

src/main/example/ChatServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public void onError( WebSocket conn, Exception ex ) {
7676
}
7777
}
7878

79+
@Override
80+
public void onStart() {
81+
System.out.println("Server started!");
82+
}
83+
7984
/**
8085
* Sends <var>text</var> to all currently connected WebSocket clients.
8186
*

src/main/java/org/java_websocket/drafts/Draft_10.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public static int readVersion(Handshakedata handshakedata) {
5353
}
5454

5555
private ByteBuffer incompleteframe;
56-
private Framedata fragmentedframe = null;
5756

5857
private final Random reuseableRandom = new Random();
5958

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public void run() {
280280
socket.bind( address );
281281
selector = Selector.open();
282282
server.register( selector, server.validOps() );
283+
onStart();
283284
} catch ( IOException ex ) {
284285
handleFatal( null, ex );
285286
return;
@@ -684,6 +685,14 @@ public InetSocketAddress getRemoteSocketAddress( WebSocket conn ) {
684685
* Can be null if there error does not belong to one specific websocket. For example if the servers port could not be bound.
685686
**/
686687
public abstract void onError( WebSocket conn, Exception ex );
688+
689+
/**
690+
* Called when the server started up successfully.
691+
*
692+
* If any error occured, onError is called instead.
693+
*/
694+
public abstract void onStart();
695+
687696
/**
688697
* Callback for binary messages received from the remote host
689698
*

src/test/java/org/java_websocket/AutobahnClientScenario.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public void onError(WebSocket conn, Exception ex) {
5050
//throw new UnsupportedOperationException("Not supported yet.");
5151
}
5252

53+
@Override
54+
public void onStart() {
55+
56+
}
57+
5358
}
5459

5560
private class AutobahnClient extends WebSocketClient {

src/test/java/org/java_websocket/example/AutobahnServerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public void onError( WebSocket conn, Exception ex ) {
4242
ex.printStackTrace();
4343
}
4444

45+
@Override
46+
public void onStart() {
47+
System.out.println( "Server started!" );
48+
}
49+
4550
@Override
4651
public void onMessage( WebSocket conn, String message ) {
4752
conn.send( message );

0 commit comments

Comments
 (0)