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)" );
87 "vpClient::connectToHostname()" );
93 memmove( (
char *) &serv.
receptorAddress.sin_addr.s_addr, (
char *) server->h_addr,
96 serv.
receptorIP = inet_ntoa(*(in_addr *)server->h_addr);
98 return connectServer(serv);
119 "vpClient::connectToIP()" );
128 return connectServer(serv);
141 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SHUT_RDWR );
143 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SD_BOTH );
156 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SHUT_RDWR );
158 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SD_BOTH );
178 numberOfAttempts = 15;
179 unsigned int ind = 1;
180 int connectionResult;
182 while(ind <= numberOfAttempts){
183 std::cout <<
"Attempt number " << ind <<
"..." << std::endl;
188 if(connectionResult >= 0)
195 if( connectionResult< 0 )
197 vpERROR_TRACE(
"ERROR connecting, the server may not be waiting for connection at this port.",
198 "vpClient::connectServer()");
212 std::cout <<
"Failed to set socket signal option" << std::endl;
215 #endif // SO_NOSIGPIPE
217 std::cout <<
"Connected!" << std::endl;
bool connectToHostname(const std::string &hostname, const int &port_serv)
socklen_t receptorAddressSize
virtual void print(const char *id="")
This class represents a Transmission Control Protocol (TCP) network.
int socketFileDescriptorReceptor
static int wait(double t0, double t)
bool connectToIP(const std::string &ip, const int &port_serv)
std::vector< vpReceptor > receptor_list
void deconnect(const int &index=0)
struct sockaddr_in receptorAddress