обычными TCP сокетами:
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <iostream>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
int sock;
int send_s;
int recv_s;
struct sockaddr_in saddr;
struct hostent *host;
char message[] = "Hello there!\n";
char buf[sizeof(message)];
char in [1024];
char out [1024];
if(argc != 2)
{
cout << "НЕПРАВИЛЬНО!!! ТАК ПРАВИЛЬНО: a.out <IP адрес>" << endl;
return 0;
}
if((host = gethostbyname(argv[1])) == NULL)
{
cout << "nslookup failed on '%s'\n" << argv[1] << endl;
return 0;
}
else
{
cout << "Соединение с " << argv[1] << endl;
}
sock = socket(PF_INET, SOCK_STREAM, 0);
if(sock < 0)
{
cout << "Ошибка сокета" << endl;
return 0;
}
saddr.sin_family = AF_INET;
saddr.sin_port = htons(6575); // или любой другой порт...
// saddr.sin_addr.s_addr = inet_aton("192.168.1.101");
if(inet_aton(argv[1], &saddr.sin_addr) == 0)
{
cout << "Не правильный IP адрес" << endl;
close(sock);
return 0;
}
if(connect(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
{
cout << "Connect Error" << endl;
return 0;
}
//while (1)
//{
//recv_s = recv (sock, in, 1024, 0);
//if (recv_s == -1)
//{
//cout << "Ошибка приёма" << endl;
//return 0;
//}
//if (recv_s > 0)
//{
//cout << in;
//}
//cin >> out;
//send (sock, out, 1024, 0);
//free(out);
//free(in);
//}
system ("cp1251");
cout << message << endl;
send(sock, message, sizeof(message), 0);
recv(sock, buf, sizeof(message), 0);
cout << buf << endl;
close(sock);
return 0;
}
Отправляется на эхо сервер! Приходит обратно лабуда!!!
P.S. А на всех серверах, по всем протоколам одна кодировка используется?