Go to the documentation of this file.
11 #include <mrpt/config.h>
46 #if MRPT_WORD_SIZE == 64
65 size_t Read(
void* Buffer,
size_t Count)
override;
73 size_t Write(
const void* Buffer,
size_t Count)
override;
95 const std::string& remotePartAddress,
unsigned short remotePartTCPPort,
96 unsigned int timeout_ms = 0);
135 void* Buffer,
const size_t Count,
const int timeoutStart_ms = -1,
136 const int timeoutBetween_ms = -1);
150 const void* Buffer,
const size_t Count,
const int timeout_ms = -1);
159 template <
class MESSAGE>
160 bool sendMessage(
const MESSAGE& outMsg,
const int timeout_ms = -1)
163 const char* magic =
"MRPTMessage";
166 if (written != toWrite)
return false;
168 toWrite =
sizeof(outMsg.type);
169 written =
writeAsync(&outMsg.type, toWrite, timeout_ms);
170 if (written != toWrite)
return false;
172 uint32_t contentLen = outMsg.content.size();
173 toWrite =
sizeof(contentLen);
174 written =
writeAsync(&contentLen, toWrite, timeout_ms);
175 if (written != toWrite)
return false;
177 toWrite = contentLen;
178 written =
writeAsync(&outMsg.content[0], toWrite, timeout_ms);
179 if (written != toWrite)
return false;
193 template <
class MESSAGE>
195 MESSAGE& inMsg,
const unsigned int timeoutStart_ms = 100,
196 const unsigned int timeoutBetween_ms = 1000)
202 readAsync(magic, toRead, timeoutStart_ms, timeoutBetween_ms);
203 if (actRead != toRead)
return false;
206 if (0 != ::strcmp(
"MRPTMessage", magic))
return false;
208 toRead =
sizeof(inMsg.type);
210 &inMsg.type, toRead, timeoutBetween_ms, timeoutBetween_ms);
211 if (actRead != toRead)
return false;
214 toRead =
sizeof(contentLen);
216 &contentLen, toRead, timeoutBetween_ms, timeoutBetween_ms);
217 if (actRead != toRead)
return false;
218 inMsg.content.resize(contentLen);
222 &inMsg.content[0], toRead, timeoutBetween_ms, timeoutBetween_ms);
223 if (actRead != toRead)
return false;
size_t Read(void *Buffer, size_t Count) override
Introduces a virtual method responsible for reading from the stream (This method BLOCKS) This method ...
size_t getReadPendingBytes()
Return the number of bytes already in the receive queue (they can be read without waiting)
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
int setTCPNoDelay(const int &newValue)
Set the TCP no delay option of the protocol (Nagle algorithm).
uint64_t Seek(int64_t off, CStream::TSeekOrigin org=sFromBeginning) override
This virtual method has no effect in this implementation over a TCP socket, and its use raises an exc...
A TCP socket that can be wait for client connections to enter.
bool receiveMessage(MESSAGE &inMsg, const unsigned int timeoutStart_ms=100, const unsigned int timeoutBetween_ms=1000)
Waits for an incoming message through the TCP stream.
std::string getLastErrorStr()
Returns a description of the last Sockets error.
size_t writeAsync(const void *Buffer, const size_t Count, const int timeout_ms=-1)
A method for writing to the socket with optional timeouts.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void close()
Closes the connection.
uint64_t getTotalBytesCount() const override
This virtual method has no effect in this implementation over a TCP socket, and its use raises an exc...
unsigned short m_remotePartPort
The TCP port of the remote part of the connection.
void sendString(const std::string &str)
Writes a string to the socket.
uint32_t m_hSock
The handle for the connected TCP socket, or INVALID_SOCKET.
bool sendMessage(const MESSAGE &outMsg, const int timeout_ms=-1)
Send a message through the TCP stream.
std::string m_remotePartIP
The IP address of the remote part of the connection.
size_t Write(const void *Buffer, size_t Count) override
Introduces a virtual method responsible for writing to the stream.
int getSOSendBufffer()
Return the current size of the SO send buffer.
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
unsigned __int64 uint64_t
static unsigned int DNS_LOOKUP_TIMEOUT_MS
See description of CClientTCPSocket.
size_t readAsync(void *Buffer, const size_t Count, const int timeoutStart_ms=-1, const int timeoutBetween_ms=-1)
A method for reading from the socket with an optional timeout.
int setSOSendBufffer(const int &newValue)
Set the size of the SO send buffer.
int getTCPNoDelay()
Return the value of the TCPNoDelay option.
GLsizei const GLchar ** string
~CClientTCPSocket()
Destructor.
uint64_t getPosition() const override
This virtual method has no effect in this implementation over a TCP socket, and its use raises an exc...
bool isConnected()
Returns true if this objects represents a successfully connected socket.
unsigned __int32 uint32_t
CClientTCPSocket()
Default constructor.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |