android - 如何使用 websocket 和 socket.io 在 JAVA 中连接到 SSL?

标签 android ssl socket.io wss sslengine

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

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

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

如何在 java 中连接到 ssl?

我尝试通过 SSLEngine 更改 SocketChannel。但它没有用。

ssl channel 正常。但我无法连接这个原始的 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 存储:将 JKS 更改为 BKS,没问题。

如何包装 SocketChannel ?

(Web 浏览器有效。)

最佳答案

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

Secure WebSockets based upon Autobahn

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

关于android - 如何使用 websocket 和 socket.io 在 JAVA 中连接到 SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205952/

相关文章:

git - 服务器 SSL 证书验证失败

ssl - 它是如何工作的 : Found one SSL certificate two different chains and two different root CAs

javascript - 使用 Socket.IO 获取 404

Python:urllib.error.HTTPError:HTTP 错误 525:Origin SSL 握手错误

javascript - Angular-fullstack 生成器生产应用程序无法正确服务于 socket.io?

node.js - socket.io - 为套接字获取多个字段?

android - java.lang.illegalstateexception : a factory has already been set on this layoutinflater 异常

Android 将 map 中的多边形保存为所有设备大小相同的位图

关于覆盖资源的 Android 库

android - 将数据添加到 fragment 的 ListView