42 #include <visp/vpClient.h>
70 struct hostent *server = gethostbyname( hostname.c_str() );
74 std::string noSuchHostMessage(
"ERROR, " );
75 noSuchHostMessage.append( hostname );
76 noSuchHostMessage.append(
": no such host\n" );
78 "vpClient::connectToHostname(const std::string &hostname, const int &port_serv)" );
86 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
92 "vpClient::connectToHostname()" );
98 memmove( (
char *) &serv.
receptorAddress.sin_addr.s_addr, (
char *) server->h_addr, (
unsigned)server->h_length );
100 serv.
receptorIP = inet_ntoa(*(in_addr *)server->h_addr);
102 return connectServer(serv);
121 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
127 "vpClient::connectToIP()" );
136 return connectServer(serv);
148 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
149 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SHUT_RDWR );
151 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SD_BOTH );
163 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
164 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SHUT_RDWR );
166 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SD_BOTH );
186 numberOfAttempts = 15;
187 unsigned int ind = 1;
188 int connectionResult=-1;
190 while(ind <= numberOfAttempts){
191 std::cout <<
"Attempt number " << ind <<
"..." << std::endl;
196 if(connectionResult >= 0)
203 if( connectionResult< 0 )
205 vpERROR_TRACE(
"ERROR connecting, the server may not be waiting for connection at this port.",
206 "vpClient::connectServer()");
220 std::cout <<
"Failed to set socket signal option" << std::endl;
223 #endif // SO_NOSIGPIPE
225 std::cout <<
"Connected!" << std::endl;
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.
static int wait(double t0, double t)
bool connectToHostname(const std::string &hostname, const unsigned int &port_serv)
std::vector< vpReceptor > receptor_list
SOCKET socketFileDescriptorReceptor
struct sockaddr_in receptorAddress