【问题标题】:How can connect to SSL in JAVA with websocket and socket.io?如何使用 websocket 和 socket.io 连接到 JAVA 中的 SSL?
【发布时间】:2012-02-09 05:43:07
【问题描述】:

java中如何访问wss://协议?

我使用 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 代码不一样.. 可能问题就是这一点。怎么解决??

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/cfile25.uf@121346414D45B0960BD01B.zip

key store : 把 JKS 改成 BKS,没问题。

如何包装SocketChannel?

(网络浏览器可以正常工作。)

【问题讨论】:

  • 我想将 SocketChannel 更改为 SSLSocketChannel。但它不起作用。直到握手
  • 可能 selector.select() = 0 有问题。

标签: android ssl socket.io wss sslengine


【解决方案1】:

您可以查看我的 Autobahn WebSocket 库的分支。

Secure WebSockets based upon Autobahn

您不想在 Android 上使用 SSLEngine,因为它已损坏。

【讨论】:

    猜你喜欢
    • 2015-06-08
    • 2019-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2015-09-03
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多