Skip to content

Commit 5c88070

Browse files
author
Kristijan Sedlak
committed
fixing reconnect bug (old variables not released onClose)
1 parent 3dfc835 commit 5c88070

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/net/tootallnate/websocket/WebSocketClient.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ public abstract class WebSocketClient implements Runnable, WebSocketListener {
3232
/**
3333
* The URI this client is supposed to connect to.
3434
*/
35-
private URI uri;
35+
private URI uri = null;
3636
/**
3737
* The WebSocket instance this client object wraps.
3838
*/
39-
private WebSocket conn;
39+
private WebSocket conn = null;
4040
/**
4141
* The SocketChannel instance this client uses.
4242
*/
43-
private SocketChannel client;
43+
private SocketChannel client = null;
4444
/**
4545
* The 'Selector' used to get event keys from the underlying socket.
4646
*/
47-
private Selector selector;
47+
private Selector selector = null;
4848
/**
4949
* Keeps track of whether or not the client thread should continue running.
5050
*/
51-
private boolean running;
51+
private boolean running = false;
5252
/**
5353
* The Draft of the WebSocket protocol the Client is adhering to.
5454
*/
55-
private WebSocketDraft draft;
55+
private WebSocketDraft draft = null;
5656
/**
5757
* Number 1 used in handshake
5858
*/
@@ -120,10 +120,7 @@ public void connect() {
120120
*/
121121
public void close() throws IOException
122122
{
123-
Boolean active = running;
124-
this.running = false;
125-
126-
if (active)
123+
if (running)
127124
{
128125
selector.wakeup();
129126
conn.close();
@@ -352,15 +349,19 @@ public void onOpen(WebSocket conn) {
352349
*/
353350
public void onClose(WebSocket conn)
354351
{
355-
try
352+
if (running)
356353
{
357-
close();
358-
}
359-
catch (IOException ex)
360-
{
361-
onIOError(ex);
354+
onClose();
362355
}
363-
onClose();
356+
357+
conn = null;
358+
client = null;
359+
selector = null;
360+
running = false;
361+
draft = null;
362+
number1 = 0;
363+
number2 = 0;
364+
key3 = null;
364365
}
365366

366367
/**

0 commit comments

Comments
 (0)