43 #include <visp/vpNetwork.h>
63 WSAStartup(MAKEWORD(2,0), &WSAData);
87 bool alreadyHas =
false;
96 std::cout <<
"Server already has one request with the similar ID. Request hasn't been added." << std::endl;
129 std::cout <<
id << i <<
" : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
142 struct hostent *server = gethostbyname(name);
144 if ( server == NULL )
146 std::string noSuchHostMessage(
"ERROR, " );
147 noSuchHostMessage.append( name );
148 noSuchHostMessage.append(
": no such host\n" );
149 vpERROR_TRACE( noSuchHostMessage.c_str(),
"vpClient::getReceptorIndex()" );
152 std::string ip = inet_ntoa(*(in_addr *)server->h_addr);
199 if(size == 0 || dest > (
unsigned)sizeMinusOne)
202 vpTRACE(
"Cannot Send Request! Bad Index" );
211 for(
unsigned int i = 1 ; i < req.
size() ; i++){
219 #if ! defined(APPLE) && ! defined(WIN32)
220 flags = MSG_NOSIGNAL;
224 int value = sendto(
receptor_list[dest].socketFileDescriptorReceptor, message.c_str(), message.size(), flags,
227 int value = sendto((
unsigned)
receptor_list[dest].socketFileDescriptorReceptor, message.c_str(), (int)message.size(), flags,
290 return _handleRequests();
311 _receiveRequestFrom(receptorEmitting);
312 return _handleRequests();
335 _receiveRequestOnce();
336 return _handleFirstRequest();
361 _receiveRequestOnceFrom(receptorEmitting);
362 return _handleFirstRequest();
382 for(
unsigned int i = 0 ; i < res.size() ; i++)
408 for(
unsigned int i = 0 ; i < res.size() ; i++)
489 std::vector<int> vpNetwork::_handleRequests()
491 std::vector<int> resIndex;
492 int index = _handleFirstRequest();
496 resIndex.push_back(index);
497 index = _handleFirstRequest();
513 int vpNetwork::_handleFirstRequest()
519 if (indStart == std::string::npos && indSep == std::string::npos && indEnd == std::string::npos)
530 if(indStart == std::string::npos || indSep == std::string::npos || indEnd == std::string::npos)
533 if(indEnd < indStart)
542 if(indStart2 != std::string::npos && indStart2 < indEnd)
550 size_t deb = indStart +
beginning.size();
559 bool hasBeenFound =
false;
573 vpTRACE(
"No request corresponds to the received message");
577 size_t indDebParam = indSep +
separator.size();
581 while(indEndParam != std::string::npos)
584 request_list[(unsigned)indRequest]->addParameter(param);
585 indDebParam = indEndParam+
param_sep.size();
590 request_list[(unsigned)indRequest]->addParameter(param);
610 void vpNetwork::_receiveRequest()
612 while(_receiveRequestOnce() > 0) {};
631 void vpNetwork::_receiveRequestFrom(
const unsigned int &receptorEmitting)
633 while(_receiveRequestOnceFrom(receptorEmitting) > 0) {};
654 int vpNetwork::_receiveRequestOnce()
701 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
705 else if(numbytes > 0){
706 std::string returnVal(buf, (
unsigned int)numbytes);
738 int vpNetwork::_receiveRequestOnceFrom(
const unsigned int &receptorEmitting)
742 if(size == 0 || receptorEmitting > (
unsigned)sizeMinusOne )
745 vpTRACE(
"No receptor at the specified index!" );
778 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[receptorEmitting].receptorAddress.sin_addr) << std::endl;
782 else if(numbytes > 0){
783 std::string returnVal(buf, (
unsigned int)numbytes);
unsigned int max_size_message
int receiveRequestOnceFrom(const unsigned int &receptorEmitting)
This the request that will transit on the network.
std::vector< vpRequest * > request_list
fd_set readFileDescriptor
void print(const char *id="")
int receiveAndDecodeRequestOnceFrom(const unsigned int &receptorEmitting)
int sendRequestTo(vpRequest &req, const unsigned int &dest)
std::vector< int > receiveRequestFrom(const unsigned int &receptorEmitting)
std::vector< int > receiveAndDecodeRequestFrom(const unsigned int &receptorEmitting)
std::vector< int > receiveAndDecodeRequest()
int sendAndEncodeRequestTo(vpRequest &req, const unsigned 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 *)