用法Poco C++库创建websocket平安访问(wss)客户端__1.docx

上传人:啊飒飒 文档编号:11568424 上传时间:2021-08-24 格式:DOCX 页数:6 大小:12.41KB
返回 下载 相关 举报
用法Poco C++库创建websocket平安访问(wss)客户端__1.docx_第1页
第1页 / 共6页
用法Poco C++库创建websocket平安访问(wss)客户端__1.docx_第2页
第2页 / 共6页
用法Poco C++库创建websocket平安访问(wss)客户端__1.docx_第3页
第3页 / 共6页
用法Poco C++库创建websocket平安访问(wss)客户端__1.docx_第4页
第4页 / 共6页
用法Poco C++库创建websocket平安访问(wss)客户端__1.docx_第5页
第5页 / 共6页
亲,该文档总共6页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《用法Poco C++库创建websocket平安访问(wss)客户端__1.docx》由会员分享,可在线阅读,更多相关《用法Poco C++库创建websocket平安访问(wss)客户端__1.docx(6页珍藏版)》请在三一文库上搜索。

1、用法Poco C+库创建websocket平安访问(wss)客户端_ Poco websocket库特点: 1,用法http/https ClientSession创建websocket client 2,是同步的,这对C+桌面编程来说应当是够用的. 3,依靠openssl. 代码如下 #include stdafx.h #include iostream #include assert.h #include Poco/Net/WebSocket.h #include Poco/Net/HTTPClientSession.h #include Poco/Net/HTTPRequest.h #i

2、nclude Poco/Net/HTTPResponse.h #include Poco/Net/ServerSocket.h #include Poco/Net/NetException.h #include Poco/Exception.h #include Poco/Net/HTTPSClientSession.h #include Poco/URIStreamOpener.h #include Poco/StreamCopier.h #include Poco/Path.h #include Poco/URI.h #include Poco/SharedPtr.h #include P

3、oco/Exception.h #include Poco/Net/HTTPStreamFactory.h #include Poco/Net/HTTPSStreamFactory.h #include Poco/Net/FTPStreamFactory.h #include Poco/Net/SSLManager.h #include Poco/Net/KeyConsoleHandler.h #include Poco/Net/ConsoleCertificateHandler.h #include Poco/Net/AcceptCertificateHandler.h #include P

4、oco/Net/SecureStreamSocket.h #include Poco/Net/X509Certificate.h #include memory using Poco:Net:HTTPSClientSession; using Poco:Net:HTTPClientSession; using Poco:Net:HTTPRequest; using Poco:Net:HTTPResponse; using Poco:Net:HTTPServerRequest; using Poco:Net:HTTPServerResponse; using Poco:Net:WebSocket

5、; using Poco:Net:WebSocketException; using Poco:Exception; using Poco:URIStreamOpener; using Poco:StreamCopier; using Poco:Path; using Poco:URI; using Poco:SharedPtr; using Poco:Exception; using Poco:Net:HTTPStreamFactory; using Poco:Net:HTTPSStreamFactory; using Poco:Net:FTPStreamFactory; using Poc

6、o:Net:SSLManager; using Poco:Net:Context; using Poco:Net:KeyConsoleHandler; using Poco:Net:PrivateKeyPassphraseHandler; using Poco:Net:InvalidCertificateHandler; using Poco:Net:ConsoleCertificateHandler; using Poco:Net:AcceptCertificateHandler; using Poco:Net:X509Certificate; int main(int argc, _TCH

7、AR* argv) char buffer1024; int flags; int n; std:string payload; try Poco:Net:initializeSSL(); SharedPtrInvalidCertificateHandler pCert = new ConsoleCertificateHandler(false); / ask the user via console Context:Ptr pContext = new Context(Context:TLSV1_CLIENT_USE, , , rootcert.pem, Context:VERIFY_REL

8、AXED, 9, false, ALL:!ADH:!LOW:!EXP:!MD5:STRENGTH); SSLManager:instance().initializeClient(0, pCert, pContext); HTTPSClientSession cs(echo.websocket.org, 443); HTTPRequest request(HTTPRequest:HTTP_GET, /,HTTP/1.1); HTTPResponse response; std:string cmd; WebSocket * ws = new WebSocket(cs, request, res

9、ponse); / Causes the timeout payload = SHAKETHAND; ws-sendFrame(payload.data(), payload.size(), WebSocket:FRAME_TEXT); n = ws-receiveFrame(buffer, sizeof(buffer), flags); std:coutreturn:std:string(buffer,n)n; ws-shutdown(); catch (Poco:Exception ex) std:cout Error: _FILE_:_LINE_: ex.displayText() n; return -1; return 0; 更多信息请查看IT技术专栏 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1