42 #include <visp/vpClient.h>
69 struct hostent *server = gethostbyname( hostname.c_str() );
73 std::string noSuchHostMessage(
"ERROR, " );
74 noSuchHostMessage.append( hostname );
75 noSuchHostMessage.append(
": no such host\n" );
77 "vpClient::connectToHostname(const std::string &hostname, const int &port_serv)" );
91 "vpClient::connectToHostname()" );
97 memmove( (
char *) &serv.
receptorAddress.sin_addr.s_addr, (
char *) server->h_addr, (
unsigned)server->h_length );
99 serv.
receptorIP = inet_ntoa(*(in_addr *)server->h_addr);
101 return connectServer(serv);
126 "vpClient::connectToIP()" );
135 return connectServer(serv);
148 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SHUT_RDWR );
150 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SD_BOTH );
163 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SHUT_RDWR );
165 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SD_BOTH );
185 numberOfAttempts = 15;
186 unsigned int ind = 1;
187 int connectionResult;
189 while(ind <= numberOfAttempts){
190 std::cout <<
"Attempt number " << ind <<
"..." << std::endl;
195 if(connectionResult >= 0)
202 if( connectionResult< 0 )
204 vpERROR_TRACE(
"ERROR connecting, the server may not be waiting for connection at this port.",
205 "vpClient::connectServer()");
219 std::cout <<
"Failed to set socket signal option" << std::endl;
222 #endif // SO_NOSIGPIPE
224 std::cout <<
"Connected!" << std::endl;
socklen_t receptorAddressSize
void print(const char *id="")
bool connectToIP(const std::string &ip, const unsigned int &port_serv)
void deconnect(const unsigned int &index=0)
This class represents a Transmission Control Protocol (TCP) network.
int socketFileDescriptorReceptor
static int wait(double t0, double t)
bool connectToHostname(const std::string &hostname, const unsigned int &port_serv)
std::vector< vpReceptor > receptor_list
struct sockaddr_in receptorAddress