我正在尝试在 java 中创建与 SSLEngine 的客户端/服务器连接。我想问一下有什么区别SSLEngine.getHandshakeStatus()
,SSLEngineResults.getHandshakeStatus().
我找到了 Nuno Santos 的关于SSLEngine
NIO API 和多路复用的示例代码。
我参考的代码是:
//some code here
SSLEngineResult.HandshakeStatus hs = engine.getHandshakeStatus();
String clientString = "";
while (hs != SSLEngineResult.HandshakeStatus.FINISHED && hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING)
{
switch (hs)
{
case NEED_UNWRAP:
if (socketChannel.read(peerNetData)< 0)
{
engine.closeInbound();
}
peerNetData.flip();
SSLEngineResult res = engine.unwrap(peerNetData, peerAppData);
peerNetData.compact();
hs = res.getHandshakeStatus();
switch (res.getStatus())
{
case OK:
//TODO something
break;
case BUFFER_UNDERFLOW:
//TODO something
break;
case BUFFER_OVERFLOW:
//TODO something
break;
case CLOSED:
//TODO something
engine.closeInbound();
break;
}
break;
//more code here
我找到的代码链接是: http ://onjava.com/pub/a/onjava/2004/11/03/ssl-nio.html?page=last&x-order=date
示例代码在参考资料部分
提前致谢!