Skip to content

Commit afa1498

Browse files
committed
WebSocketFactorys can now also be used on the client
1 parent 002ad9b commit afa1498

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/org/java_websocket/client/WebSocketClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.net.Socket;
66
import java.net.URI;
77
import java.nio.ByteBuffer;
8+
import java.nio.channels.ByteChannel;
89
import java.nio.channels.ClosedByInterruptException;
910
import java.nio.channels.NotYetConnectedException;
1011
import java.nio.channels.SelectionKey;
@@ -55,6 +56,8 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab
5556
* The SocketChannel instance this channel uses.
5657
*/
5758
private SocketChannel channel = null;
59+
60+
private ByteChannel wrappedchannel = null;
5861
/**
5962
* The 'Selector' used to get event keys from the underlying socket.
6063
*/
@@ -230,13 +233,13 @@ private final void interruptableRun() {
230233
}
231234
SelectionKey key = null;
232235
selector.select();
233-
SocketChannelIOHelper.batch( conn, channel );
236+
SocketChannelIOHelper.batch( conn, wrappedchannel );
234237
Set<SelectionKey> keys = selector.selectedKeys();
235238
Iterator<SelectionKey> i = keys.iterator();
236239
while ( i.hasNext() ) {
237240
key = i.next();
238241
i.remove();
239-
if( key.isReadable() && SocketChannelIOHelper.read( buff, this.conn, channel ) ) {
242+
if( key.isReadable() && SocketChannelIOHelper.read( buff, this.conn, wrappedchannel ) ) {
240243
conn.decode( buff );
241244
}
242245
if( !key.isValid() ) {
@@ -273,7 +276,7 @@ private void finishConnect() throws IOException , InvalidHandshakeException , In
273276
if( channel.isConnectionPending() ) {
274277
channel.finishConnect();
275278
}
276-
279+
wrappedchannel = wf.wrapChannel( channel );
277280
// Now that we're connected, re-register for only 'READ' keys.
278281
channel.register( selector, SelectionKey.OP_READ );
279282

0 commit comments

Comments
 (0)