Skip to content

Commit 9b0a4b8

Browse files
committed
made websocket client use java.net instead of java.nio (addresses TooTallNate#88,
TooTallNate#155, TooTallNate#167, TooTallNate#175, TooTallNate#177, TooTallNate#187) (changes not yet fully tested)
1 parent 6ea3658 commit 9b0a4b8

File tree

5 files changed

+120
-321
lines changed

5 files changed

+120
-321
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/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)