Skip to content

Commit 67d747d

Browse files
author
chen
committed
fix crash caused by "ETIMEDOUT (Connection timed out)"
1 parent 700bfc4 commit 67d747d

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ dependencies {
3939
//}
4040

4141
task wrapper(type: Wrapper) {
42-
gradleVersion = '1.4'
42+
gradleVersion = '2.6'
4343
}
4444

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <var>onOpen</var>, <var>onClose</var>, and <var>onMessage</var> to be
3737
* useful. An instance can send messages to it's connected server via the
3838
* <var>send</var> method.
39-
*
39+
*
4040
* @author Nathan Rajlich
4141
*/
4242
public abstract class WebSocketClient extends WebSocketAdapter implements Runnable {
@@ -111,12 +111,11 @@ public WebSocketClient( URI serverUri , Draft draft , Map<String,String> headers
111111
else{
112112
conn = (WebSocketImpl) wsfactory.createWebSocket( this, draft, channel.socket() );
113113
}
114-
115114
}
116115

117116
/**
118117
* Gets the URI that this WebSocketClient is connected to.
119-
*
118+
*
120119
* @return The <tt>URI</tt> for this WebSocketClient.
121120
*/
122121
public URI getURI() {
@@ -163,7 +162,7 @@ public void closeBlocking() throws InterruptedException {
163162

164163
/**
165164
* Sends <var>text</var> to the connected WebSocket server.
166-
*
165+
*
167166
* @param text
168167
* The String to send to the WebSocket server.
169168
*/
@@ -173,7 +172,7 @@ public void send( String text ) throws NotYetConnectedException {
173172

174173
/**
175174
* Sends <var>data</var> to the connected WebSocket server.
176-
*
175+
*
177176
* @param data
178177
* The Byte-Array of data to send to the WebSocket server.
179178
*/
@@ -191,7 +190,7 @@ public void run() {
191190

192191
}
193192

194-
private final void interruptableRun() {
193+
private void interruptableRun() {
195194
if( channel == null ) {
196195
return;// channel will be initialized in the constructor and only be null if no socket channel could be created or if blocking mode could be established
197196
}
@@ -221,6 +220,10 @@ private final void interruptableRun() {
221220
onWebsocketError( conn, e );
222221
conn.closeConnection( CloseFrame.NEVER_CONNECTED, e.getMessage() );
223222
return;
223+
} catch (/*AssertionError*/Throwable t) {
224+
onWebsocketError(conn, new Exception(t));
225+
conn.closeConnection(CloseFrame.NEVER_CONNECTED, t.getMessage());
226+
return;
224227
}
225228

226229
ByteBuffer buff = ByteBuffer.allocate( WebSocketImpl.RCVBUF );
@@ -303,7 +306,7 @@ public READYSTATE getReadyState() {
303306

304307
/**
305308
* Calls subclass' implementation of <var>onMessage</var>.
306-
*
309+
*
307310
* @param conn
308311
* @param message
309312
*/
@@ -319,7 +322,7 @@ public final void onWebsocketMessage( WebSocket conn, ByteBuffer blob ) {
319322

320323
/**
321324
* Calls subclass' implementation of <var>onOpen</var>.
322-
*
325+
*
323326
* @param conn
324327
*/
325328
@Override
@@ -330,7 +333,7 @@ public final void onWebsocketOpen( WebSocket conn, Handshakedata handshake ) {
330333

331334
/**
332335
* Calls subclass' implementation of <var>onClose</var>.
333-
*
336+
*
334337
* @param conn
335338
*/
336339
@Override
@@ -344,7 +347,7 @@ public final void onWebsocketClose( WebSocket conn, int code, String reason, boo
344347

345348
/**
346349
* Calls subclass' implementation of <var>onIOError</var>.
347-
*
350+
*
348351
* @param conn
349352
*/
350353
@Override
@@ -405,7 +408,7 @@ public InetSocketAddress getRemoteSocketAddress( WebSocket conn ) {
405408
public abstract void onClose( int code, String reason, boolean remote );
406409
public abstract void onError( Exception ex );
407410
public void onMessage( ByteBuffer bytes ) {
408-
};
411+
}
409412

410413
public class DefaultClientProxyChannel extends AbstractClientProxyChannel {
411414
public DefaultClientProxyChannel( ByteChannel towrap ) {
@@ -428,7 +431,7 @@ public String buildHandShake() {
428431
}
429432

430433
public interface WebSocketClientFactory extends WebSocketFactory {
431-
public ByteChannel wrapChannel( SocketChannel channel, SelectionKey key, String host, int port ) throws IOException;
434+
ByteChannel wrapChannel( SocketChannel channel, SelectionKey key, String host, int port ) throws IOException;
432435
}
433436

434437
private class WebsocketWriteThread implements Runnable {
@@ -446,7 +449,7 @@ public void run() {
446449
}
447450
}
448451
}
449-
452+
450453
public ByteChannel createProxyChannel( ByteChannel towrap ) {
451454
if( proxyAddress != null ){
452455
return new DefaultClientProxyChannel( towrap );

0 commit comments

Comments
 (0)