Skip to content

Revert "Fix for #217 by ddrscott" #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/main/java/org/java_websocket/client/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
Expand Down Expand Up @@ -47,8 +46,7 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab

private Proxy proxy = Proxy.NO_PROXY;

private WeakReference<Thread> readThread;
private WeakReference<Thread> writeThread;
private Thread writeThread;

private Draft draft;

Expand Down Expand Up @@ -157,11 +155,10 @@ public void setTcpNoDelay( boolean tcpNoDelay ) {
* Initiates the websocket connection. This method does not block.
*/
public void connect() {
if( readThread != null )
if( writeThread != null )
throw new IllegalStateException( "WebSocketClient objects are not reuseable" );
Thread reader = new Thread( this ,"WebsocketReadThread");
reader.start();
readThread = new WeakReference<Thread>( reader );
writeThread = new Thread( this );
writeThread.start();
}

/**
Expand Down Expand Up @@ -233,9 +230,8 @@ public void run() {
return;
}

Thread write = new Thread( new WebsocketWriteThread() );
write.start();
writeThread = new WeakReference<Thread>( write );
writeThread = new Thread( new WebsocketWriteThread() );
writeThread.start();

byte[] rawbuffer = new byte[ WebSocketImpl.RCVBUF ];
int readBytes;
Expand Down Expand Up @@ -332,10 +328,8 @@ public final void onWebsocketOpen( WebSocket conn, Handshakedata handshake ) {
*/
@Override
public final void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
if( writeThread != null && writeThread.get() != null)
writeThread.get().interrupt();
if( readThread != null && readThread.get() != null)
readThread.get().interrupt();
if( writeThread != null )
writeThread.interrupt();
try {
if( socket != null )
socket.close();
Expand Down