我正在用 C++ 开发一个客户端 - 服务器程序,以将数据从一台计算机传输到另一台计算机。
一切正常,但现在我被要求让它在不同网络的计算机上工作。我到处搜索,但找不到可靠的解决方案。
我已经看到了 TCP 打孔解决方案,但似乎无法在任何地方找到如何在 C++ 中做到这一点。
我希望它像 teamviewer 一样工作,但没有中间服务器。全部以编程方式将我的客户端(在一台计算机上)连接到服务器(在不同网络中的另一台计算机上)。
#include "../include/ip_tunnel_ms_windows_20180815.h"
#include "../include/message_processor_common_20190410.h"
SOCKET clientSocket;
int n = 0;
void IPTunnel::initialize(void)
{
if (inputSignals.empty()) {
printf("server%d\n", n++);
if (!server()) {
printf("Error opening server\n");
::exit(1);
}
}
else {
printf("client%d\n", n++);
if (!client()) {
printf("Error opening client\n");
::exit(1);
}
}
}
bool IPTunnel::runBlock(void)
{
.....
(transmit data)
.....
return true;
}
void IPTunnel::terminate(void) {
closesocket(clientSocket);
WSACleanup();
}
bool IPTunnel::server() {
WSADATA wsData;
WORD ver = MAKEWORD(2, …Run Code Online (Sandbox Code Playgroud)