Skip to content

Commit f4e9b51

Browse files
committed
updated example code and moved test code into the respective maven folder
1 parent e9ba668 commit f4e9b51

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/main/example/ChatServer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.InputStreamReader;
44
import java.net.InetSocketAddress;
55
import java.net.UnknownHostException;
6-
import java.util.Set;
6+
import java.util.Collection;
77

88
import org.java_websocket.WebSocket;
99
import org.java_websocket.handshake.ClientHandshake;
@@ -61,6 +61,9 @@ public static void main( String[] args ) throws InterruptedException , IOExcepti
6161
@Override
6262
public void onError( WebSocket conn, Exception ex ) {
6363
ex.printStackTrace();
64+
if( websocket != null ) {
65+
// some errors like port binding failed may not be assignable to a specific websocket
66+
}
6467
}
6568

6669
/**
@@ -72,7 +75,7 @@ public void onError( WebSocket conn, Exception ex ) {
7275
* When socket related I/O errors occur.
7376
*/
7477
public void sendToAll( String text ) {
75-
Set<WebSocket> con = connections();
78+
Collection<WebSocket> con = connections();
7679
synchronized ( con ) {
7780
for( WebSocket c : con ) {
7881
c.send( text );

src/main/example/SSLClientExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static void main( String[] args ) throws Exception {
7777
SSLContext sslContext = null;
7878
sslContext = SSLContext.getInstance( "TLS" );
7979
sslContext.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null );
80+
// sslContext.init( null, null, null ); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
8081

8182
chatclient.setWebSocketFactory( new DefaultSSLWebSocketClientFactory( sslContext ) );
8283

src/main/example/SSLServerExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class SSLServerExample {
2121
public static void main( String[] args ) throws Exception {
2222
WebSocket.DEBUG = true;
2323

24-
ChatServer chatserver = new ChatServer( 8887 );
24+
ChatServer chatserver = new ChatServer( 8887 ); // Firefox does allow multible ssl connection only via port 443 //tested on FF16
2525

2626
// load up the key store
2727
String STORETYPE = "JKS";
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.java_websocket.client.WebSocketClient;
99
import org.java_websocket.drafts.Draft;
1010
import org.java_websocket.drafts.Draft_17;
11+
import org.java_websocket.framing.FrameBuilder;
12+
import org.java_websocket.framing.Framedata;
1113
import org.java_websocket.handshake.ServerHandshake;
1214

1315
public class AutobahnClientTest extends WebSocketClient {
@@ -120,7 +122,7 @@ public static void main( String[] args ) {
120122
e.printStackTrace();
121123
System.out.println( "URI should look like ws://localhost:8887 or wss://echo.websocket.org" );
122124
} catch ( IOException e ) {
123-
e.printStackTrace();
125+
e.printStackTrace(); // for System.in reader
124126
}
125127
System.exit( 0 );
126128
}
@@ -150,4 +152,11 @@ public void onClose( int code, String reason, boolean remote ) {
150152
System.out.println( "Closed: " + code + " " + reason );
151153
}
152154

155+
@Override
156+
public void onWebsocketMessageFragment( WebSocket conn, Framedata frame ) {
157+
FrameBuilder builder = (FrameBuilder) frame;
158+
builder.setTransferemasked( true );
159+
getConnection().sendFrame( frame );
160+
}
161+
153162
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.java_websocket.WebSocket;
77
import org.java_websocket.drafts.Draft;
88
import org.java_websocket.drafts.Draft_17;
9+
import org.java_websocket.framing.FrameBuilder;
10+
import org.java_websocket.framing.Framedata;
911
import org.java_websocket.handshake.ClientHandshake;
1012
import org.java_websocket.server.WebSocketServer;
1113

@@ -47,6 +49,13 @@ public void onMessage( WebSocket conn, ByteBuffer blob ) {
4749
conn.send( blob );
4850
}
4951

52+
@Override
53+
public void onWebsocketMessageFragment( WebSocket conn, Framedata frame ) {
54+
FrameBuilder builder = (FrameBuilder) frame;
55+
builder.setTransferemasked( false );
56+
conn.sendFrame( frame );
57+
}
58+
5059
public static void main( String[] args ) throws UnknownHostException {
5160
WebSocket.DEBUG = false;
5261
int port;

0 commit comments

Comments
 (0)