我正在使用一个名为 Lacewing 的 TCP 客户端服务器库。
http://lacewing-project.org/docs/
我注意到我发送和接收的消息都是纯文本的。鉴于我使用 TCP,有没有办法轻松加密/解密消息?我怎么能添加像 TLS en.wikipedia.org/wiki/Transport_Layer_Security 或类似的东西?
谢谢
该库非常高级,但简而言之,这里是客户端服务器:
#include <string>
#include <iostream>
#define LacewingFunction
#include "Lacewing.h"
void onReceive (Lacewing::Server &Server, Lacewing::Server::Client &Client,
char * Data, int Size) {
/* callback body */
std::cout << Data << "\n";
}
void onConnect (Lacewing::Server &Server, Lacewing::Server::Client &Client)
{
std::cout << "Connected!" << "\n";
Client.Send("TestingS");
}
void onReceiveC (Lacewing::Client &Client, char * Data, int Size)
{
std::cout << Data << "\n";
Client.Send("TesingC");
}
int main(int argc, char* argv[])
{
std::string s;
std::cin >> s;
if(s == "server")
{
Lacewing::EventPump pump;
Lacewing::Server* server = new Lacewing::Server(pump);
server->onReceive(onReceive);
server->onConnect(onConnect);
server->Host(1234);
pump.StartEventLoop();
}
else
{
Lacewing::EventPump pump;
Lacewing::Client* server = new Lacewing::Client(pump);
server->onReceive(onReceiveC);
server->Connect("192.168.2.12",1234);
pump.StartEventLoop();
}
return 0;
}