Skip to content

Commit 6042525

Browse files
committed
Merge branch 'Davidiusdadi/master'
2 parents aef9229 + de9955a commit 6042525

File tree

8 files changed

+194
-366
lines changed

8 files changed

+194
-366
lines changed
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import java.net.InetSocketAddress;
2+
import java.net.Proxy;
23
import java.net.URI;
34
import java.net.URISyntaxException;
4-
import java.nio.channels.ByteChannel;
5-
6-
public class ProxyClientExample extends ExampleClient {
7-
8-
public ProxyClientExample( URI serverURI , InetSocketAddress proxy ) {
9-
super( serverURI );
10-
setProxy( proxy );
11-
}
12-
13-
@Override
14-
public ByteChannel createProxyChannel( ByteChannel towrap ) {
15-
/*
16-
* You can create custom proxy handshake here.
17-
* For more infos see: WebSocketClient.DefaultClientProxyChannel and http://tools.ietf.org/html/rfc6455#section-4.1
18-
*/
19-
return super.createProxyChannel( towrap );
20-
}
215

6+
public class ProxyClientExample {
227
public static void main( String[] args ) throws URISyntaxException {
23-
ProxyClientExample c = new ProxyClientExample( new URI( "ws://echo.websocket.org" ), new InetSocketAddress( "proxyaddress", 80 ) );// don't forget to change "proxyaddress"
8+
ExampleClient c = new ExampleClient( new URI( "ws://echo.websocket.org" ) );
9+
c.setProxy( new Proxy( Proxy.Type.HTTP, new InetSocketAddress( "proxyaddress", 80 ) ) );
2410
c.connect();
2511
}
2612
}

src/main/example/SSLClientExample.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import javax.net.ssl.KeyManagerFactory;
99
import javax.net.ssl.SSLContext;
10+
import javax.net.ssl.SSLSocketFactory;
1011
import javax.net.ssl.TrustManagerFactory;
1112

1213
import org.java_websocket.WebSocketImpl;
13-
import org.java_websocket.client.DefaultSSLWebSocketClientFactory;
1414
import org.java_websocket.client.WebSocketClient;
1515
import org.java_websocket.handshake.ServerHandshake;
1616

@@ -79,7 +79,9 @@ public static void main( String[] args ) throws Exception {
7979
sslContext.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null );
8080
// sslContext.init( null, null, null ); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
8181

82-
chatclient.setWebSocketFactory( new DefaultSSLWebSocketClientFactory( sslContext ) );
82+
SSLSocketFactory factory = sslContext.getSocketFactory();// (SSLSocketFactory) SSLSocketFactory.getDefault();
83+
84+
chatclient.setSocket( factory.createSocket() );
8385

8486
chatclient.connectBlocking();
8587

src/main/java/org/java_websocket/SocketChannelIOHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws
5959
} while ( buffer != null );
6060
}
6161

62-
if( ws.outQueue.isEmpty() && ws.isFlushAndClose() /*&& ( c == null || c.isNeedWrite() )*/) {
62+
/*if( ws.outQueue.isEmpty() && ws.isFlushAndClose() ) {//
6363
synchronized ( ws ) {
6464
ws.closeConnection();
6565
}
66-
}
66+
}*/
6767
return c != null ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
6868
}
6969

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,11 @@ public WebSocketImpl( WebSocketListener listener , List<Draft> drafts , Socket s
151151
public void decode( ByteBuffer socketBuffer ) {
152152
assert ( socketBuffer.hasRemaining() );
153153

154-
if( flushandclosestate ) {
155-
return;
156-
}
157-
158154
if( DEBUG )
159155
System.out.println( "process(" + socketBuffer.remaining() + "): {" + ( socketBuffer.remaining() > 1000 ? "too big to display" : new String( socketBuffer.array(), socketBuffer.position(), socketBuffer.remaining() ) ) + "}" );
160156

161-
if( readystate == READYSTATE.OPEN ) {
162-
decodeFrames( socketBuffer );
157+
if( readystate != READYSTATE.NOT_YET_CONNECTED ) {
158+
decodeFrames( socketBuffer );;
163159
} else {
164160
if( decodeHandshake( socketBuffer ) ) {
165161
assert ( tmpHandshakeBytes.hasRemaining() != socketBuffer.hasRemaining() || !socketBuffer.hasRemaining() ); // the buffers will never have remaining bytes at the same time
@@ -319,17 +315,13 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
319315
}
320316

321317
private void decodeFrames( ByteBuffer socketBuffer ) {
322-
if( flushandclosestate )
323-
return;
324318

325319
List<Framedata> frames;
326320
try {
327321
frames = draft.translateFrame( socketBuffer );
328322
for( Framedata f : frames ) {
329323
if( DEBUG )
330324
System.out.println( "matched frame: " + f );
331-
if( flushandclosestate )
332-
return;
333325
Opcode curop = f.getOpcode();
334326
boolean fin = f.isFin();
335327

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

Lines changed: 0 additions & 52 deletions
This file was deleted.

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)