38 #include <visp3/core/vpClient.h>
66 struct hostent *server = gethostbyname( hostname.c_str() );
70 std::string noSuchHostMessage(
"ERROR, " );
71 noSuchHostMessage.append( hostname );
72 noSuchHostMessage.append(
": no such host\n" );
74 "vpClient::connectToHostname(const std::string &hostname, const int &port_serv)" );
82 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
88 "vpClient::connectToHostname()" );
94 memmove( (
char *) &serv.
receptorAddress.sin_addr.s_addr, (
char *) server->h_addr, (
unsigned)server->h_length );
96 serv.
receptorIP = inet_ntoa(*(in_addr *)server->h_addr);
98 return connectServer(serv);
117 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
123 "vpClient::connectToIP()" );
132 return connectServer(serv);
144 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
145 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SHUT_RDWR );
147 shutdown(
receptor_list[index].socketFileDescriptorReceptor, SD_BOTH );
159 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
160 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SHUT_RDWR );
162 shutdown(
receptor_list[i].socketFileDescriptorReceptor, SD_BOTH );
182 numberOfAttempts = 15;
183 unsigned int ind = 1;
184 int connectionResult=-1;
186 while(ind <= numberOfAttempts){
187 std::cout <<
"Attempt number " << ind <<
"..." << std::endl;
192 if(connectionResult >= 0)
199 if( connectionResult< 0 )
201 vpERROR_TRACE(
"ERROR connecting, the server may not be waiting for connection at this port.",
202 "vpClient::connectServer()");
216 std::cout <<
"Failed to set socket signal option" << std::endl;
219 #endif // SO_NOSIGPIPE
221 std::cout <<
"Connected!" << std::endl;
VISP_EXPORT int wait(double t0, double t)
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
bool connectToHostname(const std::string &hostname, const unsigned int &port_serv)
std::vector< vpReceptor > receptor_list
struct sockaddr_in receptorAddress