Skip to content

Commit

Permalink
Merge branch 'Davidiusdadi/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidiusdadi committed Sep 22, 2013
2 parents aef9229 + de9955a commit 6042525
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 366 deletions.
22 changes: 4 additions & 18 deletions src/main/example/ProxyClientExample.java
@@ -1,26 +1,12 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.ByteChannel;

public class ProxyClientExample extends ExampleClient {

public ProxyClientExample( URI serverURI , InetSocketAddress proxy ) {
super( serverURI );
setProxy( proxy );
}

@Override
public ByteChannel createProxyChannel( ByteChannel towrap ) {
/*
* You can create custom proxy handshake here.
* For more infos see: WebSocketClient.DefaultClientProxyChannel and http://tools.ietf.org/html/rfc6455#section-4.1
*/
return super.createProxyChannel( towrap );
}

public class ProxyClientExample {
public static void main( String[] args ) throws URISyntaxException {
ProxyClientExample c = new ProxyClientExample( new URI( "ws://echo.websocket.org" ), new InetSocketAddress( "proxyaddress", 80 ) );// don't forget to change "proxyaddress"
ExampleClient c = new ExampleClient( new URI( "ws://echo.websocket.org" ) );
c.setProxy( new Proxy( Proxy.Type.HTTP, new InetSocketAddress( "proxyaddress", 80 ) ) );
c.connect();
}
}
6 changes: 4 additions & 2 deletions src/main/example/SSLClientExample.java
Expand Up @@ -7,10 +7,10 @@

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;

import org.java_websocket.WebSocketImpl;
import org.java_websocket.client.DefaultSSLWebSocketClientFactory;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

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

chatclient.setWebSocketFactory( new DefaultSSLWebSocketClientFactory( sslContext ) );
SSLSocketFactory factory = sslContext.getSocketFactory();// (SSLSocketFactory) SSLSocketFactory.getDefault();

chatclient.setSocket( factory.createSocket() );

chatclient.connectBlocking();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/java_websocket/SocketChannelIOHelper.java
Expand Up @@ -59,11 +59,11 @@ public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws
} while ( buffer != null );
}

if( ws.outQueue.isEmpty() && ws.isFlushAndClose() /*&& ( c == null || c.isNeedWrite() )*/) {
/*if( ws.outQueue.isEmpty() && ws.isFlushAndClose() ) {//
synchronized ( ws ) {
ws.closeConnection();
}
}
}*/
return c != null ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
}

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Expand Up @@ -151,15 +151,11 @@ public WebSocketImpl( WebSocketListener listener , List<Draft> drafts , Socket s
public void decode( ByteBuffer socketBuffer ) {
assert ( socketBuffer.hasRemaining() );

if( flushandclosestate ) {
return;
}

if( DEBUG )
System.out.println( "process(" + socketBuffer.remaining() + "): {" + ( socketBuffer.remaining() > 1000 ? "too big to display" : new String( socketBuffer.array(), socketBuffer.position(), socketBuffer.remaining() ) ) + "}" );

if( readystate == READYSTATE.OPEN ) {
decodeFrames( socketBuffer );
if( readystate != READYSTATE.NOT_YET_CONNECTED ) {
decodeFrames( socketBuffer );;
} else {
if( decodeHandshake( socketBuffer ) ) {
assert ( tmpHandshakeBytes.hasRemaining() != socketBuffer.hasRemaining() || !socketBuffer.hasRemaining() ); // the buffers will never have remaining bytes at the same time
Expand Down Expand Up @@ -319,17 +315,13 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
}

private void decodeFrames( ByteBuffer socketBuffer ) {
if( flushandclosestate )
return;

List<Framedata> frames;
try {
frames = draft.translateFrame( socketBuffer );
for( Framedata f : frames ) {
if( DEBUG )
System.out.println( "matched frame: " + f );
if( flushandclosestate )
return;
Opcode curop = f.getOpcode();
boolean fin = f.isFin();

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 6042525

Please sign in to comment.