22
33import java .io .File ;
44import java .io .FileInputStream ;
5+ import java .io .IOException ;
56import java .net .InetAddress ;
67import java .net .InetSocketAddress ;
78import java .net .Socket ;
9+ import java .nio .channels .ByteChannel ;
810import java .nio .channels .SocketChannel ;
911import java .security .KeyStore ;
1012import 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
0 commit comments