2012-02-09 3 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(); 
} 

이 점은 어때? 나도 몰라. 원래 websocket 코드가 같지 않다. 문제는이 시점이다. 어떻게 고칠 수 있니? BKS로 변경 JKS하지 문제 :

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]

키 저장소입니다.

어떻게 SocketChannel을 감쌀 수 있습니까?

(웹 브라우저는했다.)

+0

SocketChannel을 SSLSocketChannel로 변경하려고합니다. 하지만 작동하지 않습니다. 핸드 셰이크 –

+0

어쩌면 selector.select() = 0 문제. –

답변

2

당신은 아우토반 웹 소켓 라이브러리 내 포크를 확인할 수 있습니다. 이 고장 때문에

Secure WebSockets based upon Autobahn

당신은 안드로이드에 SSLEngine의를 사용하지 않습니다.

관련 문제