Skip to content

Commit e9424f1

Browse files
committed
minor improvements
1 parent 8f17f24 commit e9424f1

6 files changed

Lines changed: 209 additions & 181 deletions

File tree

example/ChatServer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import java.io.BufferedReader;
22
import java.io.IOException;
33
import java.io.InputStreamReader;
4-
import java.net.InetAddress;
54
import java.net.InetSocketAddress;
65
import java.net.UnknownHostException;
76
import java.util.Set;
@@ -16,7 +15,7 @@
1615
public class ChatServer extends WebSocketServer {
1716

1817
public ChatServer( int port ) throws UnknownHostException {
19-
super( new InetSocketAddress( InetAddress.getByName( "localhost" ), port ) );
18+
super( new InetSocketAddress( port ) );
2019
}
2120

2221
public ChatServer( InetSocketAddress address ) {
@@ -55,7 +54,7 @@ public void onMessage( WebSocket conn, String message ) {
5554

5655
public static void main( String[] args ) throws InterruptedException , IOException {
5756
WebSocket.DEBUG = true;
58-
int port = 8887;
57+
int port = 8887; // 843 flash policy port
5958
try {
6059
port = Integer.parseInt( args[ 0 ] );
6160
} catch ( Exception ex ) {

src/org/java_websocket/WebSocket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum Role {
1616
CLIENT, SERVER
1717
}
1818

19-
public static int BUFFERSIZE = 512;
19+
public static int RCVBUF = 512;
2020

2121
public static/*final*/boolean DEBUG = false; // must be final in the future in order to take advantage of VM optimization
2222

src/org/java_websocket/WebSocketClient.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.nio.channels.SocketChannel;
1212
import java.nio.channels.UnresolvedAddressException;
1313
import java.util.Iterator;
14+
import java.util.List;
1415
import java.util.Map;
1516
import java.util.Set;
1617
import java.util.concurrent.locks.Lock;
@@ -61,6 +62,18 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab
6162

6263
private Map<String, String> headers;
6364

65+
WebSocketFactory wf = new WebSocketFactory() {
66+
@Override
67+
public WebSocket createWebSocket( WebSocketAdapter a, Draft d, SocketChannel c ) {
68+
return new WebSocketImpl( WebSocketClient.this, d, c );
69+
}
70+
71+
@Override
72+
public WebSocket createWebSocket( WebSocketAdapter a, List<Draft> d, SocketChannel c ) {
73+
return new WebSocketImpl( WebSocketClient.this, d, c );
74+
}
75+
};
76+
6477
public WebSocketClient( URI serverURI ) {
6578
this( serverURI, new Draft_10() );
6679
}
@@ -182,7 +195,7 @@ protected final void interruptableRun() {
182195
onWebsocketError( conn, e );
183196
return;
184197
}
185-
conn = new WebSocketImpl( this, draft, client );
198+
conn = (WebSocketImpl) wf.createWebSocket( this, draft, client );
186199
try/*IO*/{
187200
while ( !conn.isClosed() ) {
188201
if( Thread.interrupted() ) {
@@ -197,7 +210,8 @@ protected final void interruptableRun() {
197210
key = i.next();
198211
i.remove();
199212
if( key.isReadable() ) {
200-
conn.handleRead();
213+
conn.read();
214+
conn.decode();
201215
}
202216
if( !key.isValid() ) {
203217
continue;
@@ -375,6 +389,14 @@ public WebSocket getConnection() {
375389
return conn;
376390
}
377391

392+
public final void setWebSocketFactory( WebSocketFactory wsf ) {
393+
this.wf = wsf;
394+
}
395+
396+
public final WebSocketFactory getWebSocketFactory() {
397+
return wf;
398+
}
399+
378400
// ABTRACT METHODS /////////////////////////////////////////////////////////
379401
public abstract void onOpen( ServerHandshake handshakedata );
380402
public abstract void onMessage( String message );

src/org/java_websocket/WebSocketFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
public interface WebSocketFactory {
99
public WebSocket createWebSocket( WebSocketAdapter a, Draft d, SocketChannel c );
10-
public WebSocket createWebSocket( WebSocketServer a, List<Draft> drafts, SocketChannel c );
10+
public WebSocket createWebSocket( WebSocketAdapter a, List<Draft> drafts, SocketChannel c );
1111
}

0 commit comments

Comments
 (0)