资源简介
这个是一个结合了OpenSSL 和 IOCP的一个例子,需要的可以参考一下的。
代码片段和文件信息
// client.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include se.h>
#include
#include “../shared/openssl_iocp.h“
CHandle connect_event(CreateEvent(0 FALSE FALSE 0));
CHandle close_event(CreateEvent(0 TRUE FALSE 0));
session *g_psession = nullptr;
void app_on_session_connect(session *psession)
{
if(psession->status & CONNECTED)
{
printf(“Connected to %s\n“ psession->addresses_sz[REMOTE]);
X509* cert = SSL_get_peer_certificate(psession->ssl);
ssl_print_cert_info(cert);
printf(“Type message to be sent to server and press ENTER empty message to exit\n“);
}
else
printf(“Failed to connect %s\n“ psession->addresses_sz[REMOTE]);
SetEvent(connect_event);
}
void app_on_session_send(session *psession)
{
}
void app_on_session_recv(session *psession)
{
printf(“Received %d bytes from %s:“ psession->ssl_buffer_size[RECV] psession->addresses_sz[REMOTE]);
char buffer[BUFFER_SIZE+1] = {0};
strncpy_s(buffer psession->ssl_buffer[RECV] psession->ssl_buffer_size[RECV]);
buffer[psession->ssl_buffer_size[RECV]] = 0;
printf(“%s\n“ buffer);
}
void app_on_session_close(session *psession)
{
printf(“Session %s - %s is closed\n“ psession->addresses_sz[LOCAL] psession->addresses_sz[REMOTE]);
SetEvent(close_event);
}
int _tmain(int argc _TCHAR* argv[])
{
ssl_init();
if(argc >= 2)
{
sockaddr_storage addr = {0};
sockaddr_in *paddrin = (sockaddr_in*)&addr;
addrinfo hints = {0};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
addrinfo *paddrinfo = 0;
if(0 == getaddrinfo(CW2A(argv[1]) ““ &hints &paddrinfo))
{
for(addrinfo *p = paddrinfo; p != 0; p = p->ai_next)
{
memcpy_s(&addr sizeof(addr) p->ai_addr p->ai_addrlen);
break;
}
freeaddrinfo(paddrinfo);
paddrin->sin_port = htons(443);
if(argc == 3)
{
int port = _wtol(argv[2]);
if(port > 0 && port < 65535)
paddrin->sin_port = htons(port);
}
// create a new session object and initiate connection
g_psession = session_new();
session_connect(g_psession &addr);
// wait for connection to finish (either succeeded or failed)
WaitForSingleobject(connect_event INFINITE);
while(true)
{
char data[BUFFER_SIZE];
gets_s(data);
// connection has been closed (either by us or server) exit from loop
if(WAIT_object_0 == WaitForSingleobject(close_event 0))
break;
// if input string is empty close the connection to server
int len = strlen(data);
if(len == 0)
{
session_lock(g_psession);
session_close(g_psession);
session_unlock(g_psession);
break;
}
// send input string to server
session_send_data(g_psession data len);
}
// wait for connection to be closed and all pending operations have finished or been cancelle
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-02-28 06:38 client\
文件 3328 2013-02-28 05:46 client\client.cpp
文件 5331 2013-02-27 03:49 client\client.vcxproj
文件 909 2013-02-26 08:30 client\client.vcxproj.filters
文件 293 2013-02-26 08:22 client\stdafx.cpp
文件 320 2013-02-26 08:22 client\stdafx.h
文件 314 2013-02-26 08:22 client\targetver.h
目录 0 2013-02-27 03:44 openssl\
目录 0 2013-02-27 03:43 openssl\include\
目录 0 2013-02-27 03:43 openssl\include\openssl\
文件 5653 2013-02-12 00:08 openssl\include\openssl\aes.h
文件 2986 2013-02-12 00:08 openssl\include\openssl\appli
文件 53578 2013-02-12 00:08 openssl\include\openssl\asn1.h
文件 31029 2013-02-12 00:08 openssl\include\openssl\asn1t.h
文件 19714 2013-02-12 00:08 openssl\include\openssl\asn1_mac.h
文件 33820 2013-02-12 00:08 openssl\include\openssl\bio.h
文件 5265 2013-02-12 00:08 openssl\include\openssl\blowfish.h
文件 37063 2013-02-12 00:08 openssl\include\openssl\bn.h
文件 4759 2013-02-12 00:08 openssl\include\openssl\buffer.h
文件 5084 2013-02-12 00:08 openssl\include\openssl\camellia.h
文件 4591 2013-02-12 00:08 openssl\include\openssl\cast.h
文件 3324 2013-02-12 00:08 openssl\include\openssl\cmac.h
文件 20420 2013-02-12 00:08 openssl\include\openssl\cms.h
文件 2058 2013-02-12 00:08 openssl\include\openssl\comp.h
文件 10103 2013-02-12 00:08 openssl\include\openssl\conf.h
文件 4163 2013-02-12 00:08 openssl\include\openssl\conf_api.h
文件 24939 2013-02-12 00:08 openssl\include\openssl\crypto.h
文件 11090 2013-02-12 00:08 openssl\include\openssl\des.h
文件 18677 2013-02-12 00:08 openssl\include\openssl\des_old.h
文件 10250 2013-02-12 00:08 openssl\include\openssl\dh.h
文件 12378 2013-02-12 00:08 openssl\include\openssl\dsa.h
............此处省略75个文件信息
相关资源
- Win7下通过VS2015编译好的最新OpenSSL-1
- Win7下通过VS2015编译好的OpenSSL所有共八
- Windows系统下tensorflow版本的YOLO v3
- Windows程序设计 中文版+英文版+全书源
-
Ghostsc
ript 9.22 for Windows (64 bit) - masm for windows破解版
- Windows PowerShell实战指南中文第2版非扫
- Hopper Disassembler v2.8.1 For Windows Crack
- 收藏奉献_DOS汉字系统12:WPS 1.0 for w
- 地磁算法_Windows
- tomcat1.6 Windows32位及64位
- Windows设备驱动程序WDF开发清晰完全版
- windows-usb数据监视器
- mongodb 视图工具robomongo
- Windows XLIVE 3.2.3.0 适用win10
- TIandSI 3.0 windows
- Debugging Tools for Windows (x64)
- SU-FTP-Server-Windows-15.0.1安装包+注册机
- cmake-3.16.4-win64-x64.zip
- apache-tomcat-6.0.53 linux+windows64版本+对应
- apache-tomcat-8.5.46-windows-x64.zip
- 运行在windows7 64位下的autocad R14 汉化绿
- Git官方最新版 Git-2.17.0-64-bit 64位Wind
- ippicv_windows_20151201.zip
- QTMinGw下已经编译好的gdal库
- Git for windows 10 64
- graphviz.msi windows安装文件
- ogg112101_ggs_Windows_x64_ora11g_64bit.zip
- Intel SGX PSW for Windows v2.0.101.44269
- Redis-Windows中文客户端工具
评论
共有 条评论