本文整理汇总了C++中SSLSocket::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ SSLSocket::Connect方法的具体用法?C++ SSLSocket::Connect怎么用?C++ SSLSocket::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSLSocket
的用法示例。
在下文中一共展示了SSLSocket::Connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: context
// Connect EALREADY
TEST_F(SSLClientServerConnectionTest, ConnectEalready) {
MockHandler ch;
SSLContext context(SSLContext::TLSv1_1);
context.SetCertificate(std::string(CLIENT_CERT));
context.SetPrivateKey(std::string(CLIENT_PKEY));
context.SetCAFile(std::string(CA_CERT));
context.SetCiphers(std::string(CIPHER_LIST));
context.SetVerifyMode(SSLContext::VERIFY_PEER);
SSLClient cl(ch, context);
MockHandler sh;
SSLContext server_context(SSLContext::TLSv1_1);
server_context.SetCertificate(std::string(SERVER_CERT));
server_context.SetPrivateKey(std::string(SERVER_PKEY));
server_context.SetCAFile(std::string(CA_CERT));
server_context.SetCiphers(std::string(CIPHER_LIST));
server_context.SetVerifyMode(SSLContext::VERIFY_PEER);
SSLServer sv(sh, server_context);
Error e = sv.Start(TEST_ADDR, TEST_PORT);
ASSERT_EQ(LNR_OK, e.Code());
SSLSocket cs = cl.CreateSocket(TEST_ADDR, TEST_PORT);
EXPECT_CALL(sh, OnConnectMock(_)).WillOnce(Assign(&srv_finished, true));
EXPECT_CALL(ch, OnConnectMock(cs)).WillOnce(Assign(&cli_finished, true));
e = cs.Connect();
ASSERT_EQ(LNR_OK, e.Code());
WAIT_TO_FINISH_CALLBACK();
e = cs.Connect();
ASSERT_EQ(LNR_EALREADY, e.Code());
}
示例2: main
int main()
{
#if 1
//string ip = "service.evchong.com";
string ip = "123.59.53.85";
string buf;
string url;
string param;
HttpsPost httpspost;
do
{
//int ret = httpspost.Connect(ip, 443, HOSTNAME_TYPE);
int ret = httpspost.Connect(ip, 443, IP_TYPE);
if( HTTPS_CONNECTED == ret)
{
break;
}
else if( HTTPS_CONNECT_FALSE == ret)
{
break;
}
// 防止死循环,设置超时或者尝试次数,close break
}while(1);
#if 1
int ok_couter = 0;
int false_couter = 0;
int connectCouter = 1;
/*
while(1)
{
httpspost.State();
ok_couter++;
cout<< ok_couter<< endl;
sleep(1);
}
*/
while(1)
{
// heartbeat
url = "https://service.evchong.com:443/evchong_API/evchong/v1/heartbeat";
param = "{\"chargeBoxSerialNumber\":{\"chargeBoxSerialNumber\":\"1012090561\"},\"chargePointSerialNumber\":{\"chargePointSerialNumber\":\"CSN00001\"}}";
httpspost.State();
//if(httpspost.State() == HTTPS_FREE)
{
do
{
//int ret = httpspost.Connect(ip, 443, HOSTNAME_TYPE);
int ret = httpspost.Connect(ip, 443, IP_TYPE);
if( HTTPS_CONNECTED == ret)
{
connectCouter++;
break;
}
else if( HTTPS_CONNECT_FALSE == ret)
{
break;
}
// 防止死循环,设置超时或者尝试次数,close break
}while(1);
}
if( HTTPS_SENTED == httpspost.Send(url, param) )
{
cout<< ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> send heartbeat" << endl;
while(1)
{
int ret = httpspost.Recv(buf);
if(HTTPS_RECVED == ret)
{
ok_couter++;
//cout<< ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> revc heartbeat " << endl;
//cout<< "response: " << endl << buf << endl;
break;
}
else if(HTTPS_RECV_FALSE == ret)
{
false_couter++;
httpspost.Close();
//cout<< ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> recv heartbeat false and close" << endl;
break;
}
}
}
cout<<"connectCouter = "<< connectCouter << ", false_couter = " << false_couter << ", ok_couter = " << ok_couter << endl;
sleep(65);
}
#endif
//.........这里部分代码省略.........