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/