12 #include <arpa/inet.h> 13 #include <netinet/in.h> 14 #include <netinet/tcp.h> 15 #include <sys/socket.h> 16 #include <sys/types.h> 21 #include "spineMLLogging.h" 47 NetworkClient(
const std::string &hostname,
unsigned int port,
unsigned int size,
DataType dataType,
Mode mode,
const std::string &connectionName);
53 bool connect(
const std::string &hostname,
unsigned int port,
unsigned int size,
DataType dataType,
Mode mode,
const std::string &connectionName);
55 bool receive(std::vector<double> &buffer);
56 bool send(
const std::vector<double> &buffer);
62 enum class Response : char
73 int startNonBlockingSend()
77 u_long nonBlockingMode = 1;
78 ioctlsocket(m_Socket, FIONBIO, &nonBlockingMode);
88 void endNonBlockingSend()
92 u_long nonBlockingMode = 0;
93 ioctlsocket(m_Socket, FIONBIO, &nonBlockingMode);
97 template<
typename Type>
98 bool sendRequestReadResponse(Type data, Response &response)
101 const int sendFlags = startNonBlockingSend();
104 if(::
send(m_Socket, reinterpret_cast<const char*>(&data),
sizeof(Type), sendFlags) < 0) {
105 LOGE_SPINEML <<
"Unable to send request";
110 endNonBlockingSend();
113 if(::recv(m_Socket, reinterpret_cast<char*>(&response),
sizeof(Response), MSG_WAITALL) < 1) {
114 LOGE_SPINEML <<
"Unable to receive response";
121 bool sendRequestReadResponse(
const std::string &data, Response &response);
Definition: networkClient.h:27
bool receive(std::vector< double > &buffer)
Definition: networkClient.cc:116
~NetworkClient()
Definition: networkClient.cc:26
bool connect(const std::string &hostname, unsigned int port, unsigned int size, DataType dataType, Mode mode, const std::string &connectionName)
Definition: networkClient.cc:38
Definition: connectors.h:25
NetworkClient()
Definition: networkClient.cc:15
bool send(const std::vector< double > &buffer)
Definition: networkClient.cc:150
Mode
Definition: networkClient.h:33
DataType
Definition: networkClient.h:39