2012-02-09 102 views
1

如何在java中访问wss://协议?如何使用websocket和socket.io在JAVA中连接到SSL?

我使用benkay/java-socket.io.client 但它不支持wss协议。

我试过使用SSLEngine。但这是非常艰苦的工作。

如何在java中连接到ssl?

我试图通过SSLEngine更改SocketChannel。但它不起作用。

ssl通道没问题。但我无法连接这个原始的websocket部分。

这是源代码。

client = SocketChannel.open(remote); 
    client.configureBlocking(false); 
    //client.connect(remote); 

    selector = Selector.open(); 
    this.conn = new WebSocket(client, new LinkedBlockingQueue<ByteBuffer>(), this); 
    client.register(selector, SelectionKey.OP_READ); 

    try { 
    sslClient = new SSLClient(keyStore, storepass.toCharArray(), client); 
    sslClient.beginHandShake(); 
     startClient() 


} catch (Exception e) { 
    e.printStackTrace(); 
} 

这一点uncorret?我不知道..不一样的原始websocket代码..可能问题是这一点。如何解决它?

public void startClient() 
{ 
    try 
    { 
     while(true) 
     { 
      if(selector.select() <= 0) 
      { 
       continue; 
      } 

      Iterator<SelectionKey> it = selector.selectedKeys().iterator(); 

      while(it.hasNext()) 
      { 
       SelectionKey key = (SelectionKey)it.next(); 
       Log.e("key","key"); 
       if(key.isReadable()) 
       { 
        read(key); 
       } 
       it.remove(); 
      }    
     } 
    } 
    catch(Exception e) 
    { 

    } 
} 

和SSLClient是http://rapidant.tistory.com/attachment/[email protected]

密钥存储:JKS变化对BKS,没有问题。

如何包装SocketChannel?

(Web浏览器,它的工作。)

+0

我想将SocketChannel更改为SSLSocketChannel。 但它不起作用。直到握手 – 2012-02-09 08:34:44

+0

或许selector.select()= 0的问题。 – 2012-02-10 01:38:35

回答