39 #if defined(WINRT) || defined(_WIN32)
40 #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
41 #define _WINSOCK_DEPRECATED_NO_WARNINGS
45 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpDebug.h>
47 #include <visp3/core/vpRequest.h>
53 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
54 #include <sys/select.h>
58 #ifdef VISP_HAVE_FUNC_INET_NTOP
60 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
61 #include <arpa/inet.h>
63 #include <netinet/in.h>
64 #include <sys/socket.h>
73 #if defined(__APPLE__) && defined(__MACH__)
74 #include <TargetConditionals.h>
98 #ifndef DOXYGEN_SHOULD_SKIP_THIS
101 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
102 int socketFileDescriptorReceptor;
103 socklen_t receptorAddressSize;
105 SOCKET socketFileDescriptorReceptor;
106 int receptorAddressSize;
108 struct sockaddr_in receptorAddress;
109 std::string receptorIP;
111 vpReceptor() : socketFileDescriptorReceptor(0), receptorAddressSize(), receptorAddress(), receptorIP() { }
116 struct sockaddr_in emitterAddress;
117 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
118 int socketFileDescriptorEmitter;
120 SOCKET socketFileDescriptorEmitter;
122 vpEmitter() : emitterAddress(), socketFileDescriptorEmitter(0)
124 emitterAddress.sin_family = AF_INET;
125 emitterAddress.sin_addr.s_addr = INADDR_ANY;
126 emitterAddress.sin_port = 0;
127 socketFileDescriptorEmitter = 0;
139 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
163 std::vector<int> privHandleRequests();
164 int privHandleFirstRequest();
166 void privReceiveRequest();
167 void privReceiveRequestFrom(
const unsigned int &receptorEmitting);
168 int privReceiveRequestOnce();
169 int privReceiveRequestOnceFrom(
const unsigned int &receptorEmitting);
177 int getReceptorIndex(
const char *name);
188 if (ind >= (
int)request_list.size() || ind < 0)
190 return request_list[(unsigned)ind]->getId();
202 void print(
const char *
id =
"");
204 template <
typename T>
int receive(T *
object,
const unsigned int &sizeOfObject =
sizeof(T));
205 template <
typename T>
206 int receiveFrom(T *
object,
const unsigned int &receptorEmitting,
const unsigned int &sizeOfObject =
sizeof(T));
208 std::vector<int> receiveRequest();
209 std::vector<int> receiveRequestFrom(
const unsigned int &receptorEmitting);
210 int receiveRequestOnce();
211 int receiveRequestOnceFrom(
const unsigned int &receptorEmitting);
213 std::vector<int> receiveAndDecodeRequest();
214 std::vector<int> receiveAndDecodeRequestFrom(
const unsigned int &receptorEmitting);
215 int receiveAndDecodeRequestOnce();
216 int receiveAndDecodeRequestOnceFrom(
const unsigned int &receptorEmitting);
218 void removeDecodingRequest(
const char *);
220 template <
typename T>
int send(T *
object,
const int unsigned &sizeOfObject =
sizeof(T));
221 template <
typename T>
int sendTo(T *
object,
const unsigned int &dest,
const unsigned int &sizeOfObject =
sizeof(T));
224 int sendRequestTo(
vpRequest &req,
const unsigned int &dest);
226 int sendAndEncodeRequest(
vpRequest &req);
227 int sendAndEncodeRequestTo(
vpRequest &req,
const unsigned int &dest);
294 vpTRACE(
"No receptor");
299 #ifdef TARGET_OS_IPHONE
322 vpERROR_TRACE(
"Select error");
325 else if (value == 0) {
332 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
333 numbytes = recv(
receptor_list[i].socketFileDescriptorReceptor, (
char *)(
void *)
object, sizeOfObject, 0);
335 numbytes = recv((
unsigned int)
receptor_list[i].socketFileDescriptorReceptor, (
char *)(
void *)
object,
336 (
int)sizeOfObject, 0);
339 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[i].receptorAddress.sin_addr) << std::endl;
373 template <
typename T>
378 vpTRACE(
"No receptor at the specified index");
383 #ifdef TARGET_OS_IPHONE
399 vpERROR_TRACE(
"Select error");
402 else if (value == 0) {
408 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
410 recv(
receptor_list[receptorEmitting].socketFileDescriptorReceptor, (
char *)(
void *)
object, sizeOfObject, 0);
412 numbytes = recv((
unsigned int)
receptor_list[receptorEmitting].socketFileDescriptorReceptor,
413 (
char *)(
void *)
object, (
int)sizeOfObject, 0);
416 std::cout <<
"Disconnected : " << inet_ntoa(
receptor_list[receptorEmitting].receptorAddress.sin_addr)
448 template <
typename T>
int vpNetwork::send(T *
object,
const unsigned int &sizeOfObject)
452 vpTRACE(
"No receptor !");
458 #if defined(__linux__)
459 flags = MSG_NOSIGNAL;
462 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
463 return sendto(
receptor_list[0].socketFileDescriptorReceptor, (
const char *)(
void *)
object, sizeOfObject, flags,
466 return sendto(
receptor_list[0].socketFileDescriptorReceptor, (
const char *)(
void *)
object, (
int)sizeOfObject, flags,
492 template <
typename T>
int vpNetwork::sendTo(T *
object,
const unsigned int &dest,
const unsigned int &sizeOfObject)
496 vpTRACE(
"No receptor at the specified index.");
502 #if defined(__linux__)
503 flags = MSG_NOSIGNAL;
506 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
507 return sendto(
receptor_list[dest].socketFileDescriptorReceptor, (
const char *)(
void *)
object, sizeOfObject, flags,
510 return sendto(
receptor_list[dest].socketFileDescriptorReceptor, (
const char *)(
void *)
object, (
int)sizeOfObject,
This class represents a Transmission Control Protocol (TCP) network.
int sendTo(T *object, const unsigned int &dest, const unsigned int &sizeOfObject=sizeof(T))
std::string getRequestIdFromIndex(const int &ind)
fd_set readFileDescriptor
void setTimeoutUSec(const long &usec)
int receiveFrom(T *object, const unsigned int &receptorEmitting, const unsigned int &sizeOfObject=sizeof(T))
void setVerbose(const bool &mode)
std::string currentMessageReceived
std::vector< vpRequest * > request_list
int send(T *object, const int unsigned &sizeOfObject=sizeof(T))
std::vector< vpReceptor > receptor_list
void setTimeoutSec(const long &sec)
int receive(T *object, const unsigned int &sizeOfObject=sizeof(T))
unsigned int getMaxSizeReceivedMessage()
unsigned int max_size_message
void setMaxSizeReceivedMessage(const unsigned int &s)
This the request that will transit on the network.