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
密钥库:将 JKS 更改为 BKS,没问题。
如何包装 SocketChannel ?
(网络浏览器可以工作。)