You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* A subclass must implement at least <var>onOpen</var>, <var>onClose</var>, and <var>onMessage</var> to be
29
29
* useful. At runtime the user is expected to establish a connection via {@link #connect()}, then receive events like {@link #onMessage(String)} via the overloaded methods and to {@link #send(String)} data to the server.
@@ -35,7 +35,7 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab
35
35
*/
36
36
protectedURIuri = null;
37
37
38
-
privateWebSocketImplengine = null;
38
+
privatetransientWebSocketImplengine = null;
39
39
40
40
privateSocketsocket = null;
41
41
@@ -47,6 +47,8 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab
47
47
48
48
privateThreadwriteThread;
49
49
50
+
privateThreadreadThread;
51
+
50
52
privateDraftdraft;
51
53
52
54
privateMap<String,String> headers;
@@ -103,10 +105,17 @@ public Draft getDraft() {
103
105
* Initiates the websocket connection. This method does not block.
104
106
*/
105
107
publicvoidconnect() {
106
-
if( writeThread != null )
107
-
thrownewIllegalStateException( "WebSocketClient objects are not reuseable" );
108
-
writeThread = newThread( this );
109
-
writeThread.start();
108
+
if(isOpen()||isConnecting()){
109
+
return;
110
+
}else{
111
+
if(writeThread!=null){
112
+
writeThread.interrupt();
113
+
readThread.interrupt();
114
+
this.draft = draft.copyInstance();
115
+
this.engine = newWebSocketImpl( this,this.draft);
116
+
}
117
+
newThread(this).start();
118
+
}
110
119
}
111
120
112
121
/**
@@ -136,7 +145,7 @@ public void closeBlocking() throws InterruptedException {
136
145
137
146
/**
138
147
* Sends <var>text</var> to the connected websocket server.
139
-
*
148
+
*
140
149
* @param text
141
150
* The string which will be transmitted.
142
151
*/
@@ -146,7 +155,7 @@ public void send( String text ) throws NotYetConnectedException {
146
155
147
156
/**
148
157
* Sends binary <var> data</var> to the connected webSocket server.
149
-
*
158
+
*
150
159
* @param data
151
160
* The byte-Array of data to send to the WebSocket server.
152
161
*/
@@ -156,10 +165,8 @@ public void send( byte[] data ) throws NotYetConnectedException {
0 commit comments