Если по вашему мнению эти сервера нужно использовать только для тестовГде и когда я так сказал? Не придумывайте.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
WSADATA wsaData;
int result;
result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if(result != 0)
{
cout << "Error WSAStartup: " << result << endl;
return -1;
}
string host;
cout << "Connect to:" << endl;
cout << "host: ";
cin >> host;
struct addrinfo ar_request = { 0, AF_INET, SOCK_DGRAM }, *ar_result = 0;
result = getaddrinfo(host.c_str(), "3478", &ar_request, &ar_result);
if (result != 0)
{
cout << "Error getaddrinfo: " << result << endl;
return -1;
}
int sockfd = socket(ar_result->ai_addr->sa_family, ar_result->ai_socktype, ar_result->ai_protocol);
if(sockfd < 0)
{
cout << "Error in socket(): " << WSAGetLastError() << endl;
WSACleanup();
return -1;
}
result = connect(sockfd, ar_result->ai_addr, ar_result->ai_addrlen);
if(result < 0)
{
cout << "Error in connect(): " << WSAGetLastError() << endl;
WSACleanup();
return -1;
}
freeaddrinfo(ar_result);
string data = "1234567890";
result = send(sockfd, data.c_str(), data.size(), 0);
if(result < 0)
{
cout << "Error in send(): " << WSAGetLastError() << endl;
WSACleanup();
return -1;
}
cout << "sent" << endl;
char buf[512] = "";
result = recv(sockfd, buf, 512, 0);
if(result < 0)
{
cout << "Error in recv(): " << WSAGetLastError() << endl;
WSACleanup();
return -1;
}
closesocket(sockfd);
WSACleanup();
cout << buf;
system("pause");
return 0;
}