Skip to content

Commit bdf9023

Browse files
authored
Merge pull request TooTallNate#631 from marci4/master
Adjusted JUnit test and extended javadoc
2 parents dc2e828 + f72be2e commit bdf9023

File tree

2 files changed

+368
-308
lines changed

2 files changed

+368
-308
lines changed

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ public void send( byte[] data ) throws NotYetConnectedException {
217217
engine.send( data );
218218
}
219219

220+
@Override
220221
protected Collection<WebSocket> connections() {
221222
return Collections.singletonList((WebSocket ) engine );
222223
}
223224

224-
225+
@Override
225226
public void sendPing() throws NotYetConnectedException {
226227
engine.sendPing( );
227228
}
228229

229230
public void run() {
230-
231231
InputStream istream;
232232
try {
233233
boolean isNewSocket = false;
@@ -288,6 +288,10 @@ public void run() {
288288
//assert ( socket.isClosed() );
289289
}
290290

291+
/**
292+
* Extract the specified port
293+
* @return the specified port or the default port for the specific scheme
294+
*/
291295
private int getPort() {
292296
int port = uri.getPort();
293297
if( port == -1 ) {
@@ -303,6 +307,10 @@ private int getPort() {
303307
return port;
304308
}
305309

310+
/**
311+
* Create and send the handshake to the other endpoint
312+
* @throws InvalidHandshakeException a invalid handshake was created
313+
*/
306314
private void sendHandshake() throws InvalidHandshakeException {
307315
String path;
308316
String part1 = uri.getRawPath();
@@ -441,13 +449,59 @@ public InetSocketAddress getRemoteSocketAddress( WebSocket conn ) {
441449
}
442450

443451
// ABTRACT METHODS /////////////////////////////////////////////////////////
452+
453+
/**
454+
* Called after an opening handshake has been performed and the given websocket is ready to be written on.
455+
* @param handshakedata The handshake of the websocket instance
456+
*/
444457
public abstract void onOpen( ServerHandshake handshakedata );
458+
459+
/**
460+
* Callback for string messages received from the remote host
461+
*
462+
* @see #onMessage(ByteBuffer)
463+
* @param message The UTF-8 decoded message that was received.
464+
**/
445465
public abstract void onMessage( String message );
466+
467+
/**
468+
* Called after the websocket connection has been closed.
469+
*
470+
* @param code
471+
* The codes can be looked up here: {@link CloseFrame}
472+
* @param reason
473+
* Additional information string
474+
* @param remote
475+
* Returns whether or not the closing of the connection was initiated by the remote host.
476+
**/
446477
public abstract void onClose( int code, String reason, boolean remote );
478+
479+
/**
480+
* Called when errors occurs. If an error causes the websocket connection to fail {@link #onClose(int, String, boolean)} will be called additionally.<br>
481+
* This method will be called primarily because of IO or protocol errors.<br>
482+
* If the given exception is an RuntimeException that probably means that you encountered a bug.<br>
483+
*
484+
* @param ex The exception causing this error
485+
**/
447486
public abstract void onError( Exception ex );
487+
488+
/**
489+
* Callback for binary messages received from the remote host
490+
*
491+
* @see #onMessage(String)
492+
*
493+
* @param bytes
494+
* The binary message that was received.
495+
**/
448496
public void onMessage( ByteBuffer bytes ) {
449497
//To overwrite
450498
}
499+
500+
/**
501+
* Callback for fragmented frames
502+
* @see WebSocket#sendFragmentedFrame(org.java_websocket.framing.Framedata.Opcode, ByteBuffer, boolean)
503+
* @param frame The fragmented frame
504+
*/
451505
@Deprecated
452506
public void onFragment( Framedata frame ) {
453507
//To overwrite
@@ -473,12 +527,15 @@ public void run() {
473527
} catch ( IOException e ) {
474528
handleIOException( e );
475529
} finally {
476-
closeOutputAndSocket();
530+
closeSocket();
477531
}
478532
}
479533
}
480534

481-
private void closeOutputAndSocket() {
535+
/**
536+
* Closing the socket
537+
*/
538+
private void closeSocket() {
482539
try {
483540
if( socket != null ) {
484541
socket.close();
@@ -488,6 +545,10 @@ private void closeOutputAndSocket() {
488545
}
489546
}
490547

548+
/**
549+
* Method to set a proxy for this connection
550+
* @param proxy the proxy to use for this websocket client
551+
*/
491552
public void setProxy( Proxy proxy ) {
492553
if( proxy == null )
493554
throw new IllegalArgumentException();

0 commit comments

Comments
 (0)