41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpRequest.h>
49 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
51 # include <sys/socket.h>
52 # include <netinet/in.h>
53 # include <arpa/inet.h>
62 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
63 # include <TargetConditionals.h>
85 #ifndef DOXYGEN_SHOULD_SKIP_THIS
87 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
88 int socketFileDescriptorReceptor;
89 socklen_t receptorAddressSize;
91 SOCKET socketFileDescriptorReceptor;
92 int receptorAddressSize;
94 struct sockaddr_in receptorAddress;
95 std::string receptorIP;
97 vpReceptor() : socketFileDescriptorReceptor(0), receptorAddressSize(), receptorAddress(), receptorIP() {}
101 struct sockaddr_in emitterAddress;
102 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
103 int socketFileDescriptorEmitter;
105 SOCKET socketFileDescriptorEmitter;
107 vpEmitter() : emitterAddress(), socketFileDescriptorEmitter(0)
109 emitterAddress.sin_family = AF_INET;
110 emitterAddress.sin_addr.s_addr = INADDR_ANY;
111 emitterAddress.sin_port = 0;
112 socketFileDescriptorEmitter = 0;
124 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
149 std::vector<int> _handleRequests();
150 int _handleFirstRequest();
152 void _receiveRequest();
153 void _receiveRequestFrom(
const unsigned int &receptorEmitting);
154 int _receiveRequestOnce();
155 int _receiveRequestOnceFrom(
const unsigned int &receptorEmitting);
164 int getReceptorIndex(
const char *name);
174 if(ind >= (
int)request_list.size() || ind < 0)
176 return request_list[(unsigned)ind]->getId();
188 void print(
const char *
id =
"");
191 int receive(T*
object,
const unsigned int &sizeOfObject =
sizeof(T));
193 int receiveFrom(T*
object,
const unsigned int &receptorEmitting,
const unsigned int &sizeOfObject =
sizeof(T));
195 std::vector<int> receiveRequest();
196 std::vector<int> receiveRequestFrom(
const unsigned int &receptorEmitting);
197 int receiveRequestOnce();
198 int receiveRequestOnceFrom(
const unsigned int &receptorEmitting);
200 std::vector<int> receiveAndDecodeRequest();
201 std::vector<int> receiveAndDecodeRequestFrom(
const unsigned int &receptorEmitting);
202 int receiveAndDecodeRequestOnce();
203 int receiveAndDecodeRequestOnceFrom(
const unsigned int &receptorEmitting);
205 void removeDecodingRequest(
const char *);
208 int send(T*
object,
const int unsigned &sizeOfObject =
sizeof(T));
210 int sendTo(T*
object,
const unsigned int &dest,
const unsigned int &sizeOfObject =
sizeof(T));
213 int sendRequestTo(
vpRequest &req,
const unsigned int &dest);
215 int sendAndEncodeRequest(
vpRequest &req);
216 int sendAndEncodeRequestTo(
vpRequest &req,
const unsigned int &dest);
321 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
322 numbytes = recv(
receptor_list[i].socketFileDescriptorReceptor, (
char*)(
void*)
object, sizeOfObject, 0);
324 numbytes = recv((
unsigned int)
receptor_list[i].socketFileDescriptorReceptor, (
char*)(
void*)
object, (
int)sizeOfObject, 0);
328 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
368 vpTRACE(
"No receptor at the specified index" );
398 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
399 numbytes = recv(
receptor_list[receptorEmitting].socketFileDescriptorReceptor, (
char*)(
void*)
object, sizeOfObject, 0);
401 numbytes = recv((
unsigned int)
receptor_list[receptorEmitting].socketFileDescriptorReceptor, (
char*)(
void*)
object, (
int)sizeOfObject, 0);
405 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[receptorEmitting].receptorAddress.sin_addr) << std::endl;
447 #if defined(__linux__)
448 flags = MSG_NOSIGNAL;
451 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
452 return sendto(
receptor_list[0].socketFileDescriptorReceptor, (
const char*)(
void*)
object, sizeOfObject,
455 return sendto(
receptor_list[0].socketFileDescriptorReceptor, (
const char*)(
void*)
object, (
int)sizeOfObject,
488 vpTRACE(
"No receptor at the specified index." );
494 #if defined(__linux__)
495 flags = MSG_NOSIGNAL;
498 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
499 return sendto(
receptor_list[dest].socketFileDescriptorReceptor, (
const char*)(
void*)
object, sizeOfObject,
502 return sendto(
receptor_list[dest].socketFileDescriptorReceptor, (
const char*)(
void*)
object, (
int)sizeOfObject,
unsigned int max_size_message
void setMaxSizeReceivedMessage(const unsigned int &s)
This the request that will transit on the network.
std::vector< vpRequest * > request_list
std::string getRequestIdFromIndex(const int &ind)
fd_set readFileDescriptor
This class represents a Transmission Control Protocol (TCP) network.
int send(T *object, const int unsigned &sizeOfObject=sizeof(T))
unsigned int getMaxSizeReceivedMessage()
int receive(T *object, const unsigned int &sizeOfObject=sizeof(T))
void setTimeoutUSec(const long &usec)
std::vector< vpReceptor > receptor_list
void setVerbose(const bool &mode)
void setTimeoutSec(const long &sec)
std::string currentMessageReceived
int sendTo(T *object, const unsigned int &dest, const unsigned int &sizeOfObject=sizeof(T))
int receiveFrom(T *object, const unsigned int &receptorEmitting, const unsigned int &sizeOfObject=sizeof(T))