POCO:如何正确将 StreamSocket 连接到 SecureStreamSocket
POCO: How to properly attach StreamSocket to SecureStreamSocket?
我尝试将连接的StreamSocket连接到SecureStreamSocket:
class MyConnection : public TCPServerConnection {
private:
Context::Ptr m_pContext;
public:
MyConnection(const StreamSocket& socket, Context::Ptr pContext)
: TCPServerConnection(socket),
m_pContext(pContext)
{
}
virtual void run() {
SecureStreamSocket secureSock(SecureStreamSocket::attach(socket(), m_pContext));
socket() = secureSock;
}
}
但我有SSLException:
SSL Exception [N4Poco3Net12SSLExceptionE]: error:140C5042:SSL routines:SSL_UNDEFINED_FUNCTION:called a function you should not call
执行了 SSL 库的初始化:
Poco::Net::initializeSSL(); // inside Application::initialize
SSL 初始化后初始化的上下文:
Poco::Net::Context::Ptr pContext =
new Poco::Net::Context(
Poco::Net::Context::SERVER_USE,
"server.key",
"server.crt",
"/path/to/certs/"
);
我们可以这样重写 SecureStreamSocket::attach(...):
SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, Context::Ptr pContext)
{
SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>streamSocket.impl()), pContext);
SecureStreamSocket result(pImpl);
if (pImpl->context()->isForServerUse())
pImpl->acceptSSL();
else
pImpl->connectSSL();
return result;
}
感谢这篇文章。现在它适用于服务器和客户端。
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- 在 libcurl 连接池中预创建连接
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- libcurl 和 DNS ttl 中的内部连接管理
- 如何应用 libcurl 的持久连接选项
- 提升 ASIO - io_service 不要等待连接到线程
- WinSock2:connect() 提供"连接被拒绝"
- 升压信号2将插槽传递到成员功能以断开连接