1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
if (function == "connect" ){
status_s = getaddrinfo(&host_const[0], &port_const[0], &host_info_s, &host_info_list_s);
if (status_s != 0) std::cout << "getaddrinfo error" << gai_strerror(status_s) ;
std::cout << "Creating a sending socket..." << std::endl;
socketfd_s = socket(host_info_list->ai_family, host_info_list->ai_socktype,
host_info_list->ai_protocol);
if (socketfd_s == -1) std::cout << "socket error " ;
std::cout << "Host: " << &host_const[0] << std::endl;
std::cout << "Port: " << &port_const[0] << std::endl;
std::cout << "function: " << function << std::endl;
function.erase(std::remove(function.begin(), function.end(), '\n'), function.end());
std::cout << "Connect()ing..." << std::endl;
status_s = connect(socketfd_s, host_info_list_s->ai_addr, host_info_list_s->ai_addrlen);
if (status_s == -1) std::cout << "connect error" ;
cout << "status: " << status_s;
cout << "socket connector: " << socketfd_s ;
std::cout << "client connected....." << std::endl;
}
else {//if (function != "connect" )
std::cout << "send()ing message on anwser..." << std::endl;
char *msg_s = "some_string";
int len_s;
ssize_t bytes_sent_s;
std::cout << msg_s;
len_s = strlen(msg_s);
std::cout << len_s << std::endl;
std::cout << "Message not sent...." << std::endl;
//send(socketfd_s, msg_s, len_s, 0);
bytes_sent_s = sendto(socketfd_s, msg_s, len_s, 0, host_info_list_s->ai_addr, host_info_list_s->ai_addrlen);
freeaddrinfo(host_info_list);
//close(socketfd_s);
//bytes_sent_s = send(socketfd_s, msg_s, len_s, 0);
//send(socketfd_s, msg_s, len_s, 0);
std::cout << "Message sent....\n" << std::endl;
std::cin.ignore();
cout << "param1" << socketfd_s;
cout << "param2" << len_s;
cout << "param3" << msg_s;
}
|