Skip to content

Commit 684db37

Browse files
committed
XD fixed fatal bug introduced during merging wss support
1 parent e0d6747 commit 684db37

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

example/SSLServer.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import java.io.File;
44
import java.io.FileInputStream;
5+
import java.io.IOException;
56
import java.net.InetAddress;
67
import java.net.InetSocketAddress;
78
import java.net.Socket;
9+
import java.nio.channels.ByteChannel;
810
import java.nio.channels.SocketChannel;
911
import java.security.KeyStore;
1012
import java.util.List;
@@ -34,6 +36,7 @@ public class SSLServer implements WebSocketServer.WebSocketServerFactory
3436

3537
public static void main(String[] args) throws Exception
3638
{
39+
WebSocket.DEBUG = true;
3740
new SSLServer();
3841
}
3942

@@ -66,7 +69,7 @@ void loadFromFile() throws Exception
6669
loadFromFile();
6770

6871
// create the web socket server
69-
WebSocketSource wsgateway = new WebSocketSource(8001, InetAddress.getByName("127.0.0.1"));
72+
WebSocketSource wsgateway = new WebSocketSource( 8887, InetAddress.getByName( "localhost" ) );
7073
wsgateway.setWebSocketFactory(this);
7174
wsgateway.start();
7275
}
@@ -89,16 +92,12 @@ public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> d, Socket
8992
}
9093

9194
@Override
92-
public SocketChannel wrapChannel( SocketChannel c ) {
93-
if( sslContext != null )
94-
try {
95-
SSLEngine e = sslContext.createSSLEngine();
96-
e.setUseClientMode( false );
97-
new SSLSocketChannel( c, e );
98-
} catch ( Exception e1 ) {
99-
}
100-
101-
return c;
95+
public ByteChannel wrapChannel( SocketChannel c ) throws IOException {
96+
if( sslContext == null )
97+
throw new IllegalArgumentException( "sslContext not initialized");
98+
SSLEngine e = sslContext.createSSLEngine();
99+
e.setUseClientMode( false );
100+
return new SSLSocketChannel( c, e );
102101
}
103102

104103
class WebSocketSource extends WebSocketServer
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.java_websocket;
22

3+
import java.io.IOException;
34
import java.net.Socket;
5+
import java.nio.channels.ByteChannel;
46
import java.nio.channels.SocketChannel;
57
import java.util.List;
68

@@ -9,5 +11,5 @@
911
public interface WebSocketFactory {
1012
public WebSocket createWebSocket( WebSocketAdapter a, Draft d, Socket s );
1113
public WebSocket createWebSocket( WebSocketAdapter a, List<Draft> drafts, Socket s );
12-
public SocketChannel wrapChannel( SocketChannel c );
14+
public ByteChannel wrapChannel( SocketChannel c ) throws IOException;
1315
}

src/org/java_websocket/WebSocketImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.InetSocketAddress;
55
import java.net.Socket;
66
import java.nio.ByteBuffer;
7+
import java.nio.channels.ByteChannel;
78
import java.nio.channels.NotYetConnectedException;
89
import java.nio.channels.SelectionKey;
910
import java.util.ArrayList;
@@ -92,7 +93,7 @@ public class WebSocketImpl extends WebSocket {
9293

9394
public final Socket socket;
9495

95-
public Object ioobject;
96+
public ByteChannel ioobject;
9697

9798
// CONSTRUCTOR /////////////////////////////////////////////////////////////
9899
/**

0 commit comments

Comments
 (0)