42 #include <visp/vpNetwork.h>
62 WSAStartup(MAKEWORD(2,0), &WSAData);
86 bool alreadyHas =
false;
95 std::cout <<
"Server already has one request with the similar ID. Request hasn't been added." << std::endl;
128 std::cout <<
id << i <<
" : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
141 struct hostent *server = gethostbyname(name);
143 if ( server == NULL )
145 std::string noSuchHostMessage(
"ERROR, " );
146 noSuchHostMessage.append( name );
147 noSuchHostMessage.append(
": no such host\n" );
148 vpERROR_TRACE( noSuchHostMessage.c_str(),
"vpClient::getReceptorIndex()" );
151 std::string ip = inet_ntoa(*(in_addr *)server->h_addr);
199 vpTRACE(
"Cannot Send Request! Bad Index" );
208 for(
unsigned int i = 1 ; i < req.
size() ; i++){
216 #if ! defined(APPLE) && ! defined(WIN32)
217 flags = MSG_NOSIGNAL;
220 int value = sendto(
receptor_list[dest].socketFileDescriptorReceptor, message.c_str(), message.size(), flags,
282 return _handleRequests();
303 _receiveRequestFrom(receptorEmitting);
304 return _handleRequests();
327 _receiveRequestOnce();
328 return _handleFirstRequest();
353 _receiveRequestOnceFrom(receptorEmitting);
354 return _handleFirstRequest();
374 for(
unsigned int i = 0 ; i < res.size() ; i++)
400 for(
unsigned int i = 0 ; i < res.size() ; i++)
481 std::vector<int> vpNetwork::_handleRequests()
483 std::vector<int> resIndex;
484 int index = _handleFirstRequest();
488 resIndex.push_back(index);
489 index = _handleFirstRequest();
505 int vpNetwork::_handleFirstRequest()
511 if (indStart == -1 && indSep == -1 && indEnd == -1)
522 if(indStart == -1 || indSep == -1 || indEnd == -1)
525 if(indEnd < indStart)
534 if(indStart2 != -1 && indStart2 < indEnd)
551 bool hasBeenFound =
false;
565 vpTRACE(
"No request corresponds to the received message");
569 int indDebParam = indSep +
separator.size();
573 while(indEndParam != -1)
577 indDebParam = indEndParam+
param_sep.size();
602 void vpNetwork::_receiveRequest()
604 while(_receiveRequestOnce() > 0) {};
623 void vpNetwork::_receiveRequestFrom(
const int &receptorEmitting)
625 while(_receiveRequestOnceFrom(receptorEmitting) > 0) {};
646 int vpNetwork::_receiveRequestOnce()
688 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
692 else if(numbytes > 0){
693 std::string returnVal(buf, numbytes);
725 int vpNetwork::_receiveRequestOnceFrom(
const int &receptorEmitting)
730 vpTRACE(
"No receptor at the specified index!" );
760 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[receptorEmitting].receptorAddress.sin_addr) << std::endl;
764 else if(numbytes > 0){
765 std::string returnVal(buf, numbytes);
unsigned int max_size_message
This the request that will transit on the network.
std::vector< vpRequest * > request_list
fd_set readFileDescriptor
virtual void print(const char *id="")
std::vector< int > receiveAndDecodeRequestFrom(const int &receptorEmitting)
int receiveRequestOnceFrom(const int &receptorEmitting)
std::vector< int > receiveAndDecodeRequest()
int sendAndEncodeRequestTo(vpRequest &req, const int &dest)
std::vector< int > receiveRequestFrom(const int &receptorEmitting)
int sendRequestTo(vpRequest &req, const int &dest)
int receiveAndDecodeRequestOnce()
int sendAndEncodeRequest(vpRequest &req)
std::vector< int > receiveRequest()
std::vector< vpReceptor > receptor_list
int sendRequest(vpRequest &req)
void removeDecodingRequest(const char *)
std::string currentMessageReceived
int getReceptorIndex(const char *name)
void addDecodingRequest(vpRequest *)
int receiveAndDecodeRequestOnceFrom(const int &receptorEmitting)