33 #ifdef SOCKET_TEST_VERBOSE 34 printf(
"[Server] Started\n");
38 15000,
"127.0.0.1", 10,
45 std::unique_ptr<CClientTCPSocket> client = server.
accept(2000);
49 #ifdef SOCKET_TEST_VERBOSE 50 printf(
"[Server] Connection accepted\n");
59 std::this_thread::sleep_for(50ms);
62 #ifdef SOCKET_TEST_VERBOSE 63 printf(
"[Server] Finish\n");
66 catch (std::exception& e)
68 cerr << e.what() << endl;
72 printf(
"[thread_server] Runtime error!\n");
87 #ifdef SOCKET_TEST_VERBOSE 88 printf(
"[Client] Connecting\n");
91 sock.
connect(
"127.0.0.1", 15000);
93 #ifdef SOCKET_TEST_VERBOSE 94 printf(
"[Client] Connected. Waiting for a message...\n");
105 printf(
"[Client] Error receiving message!!\n");
109 #ifdef SOCKET_TEST_VERBOSE 110 printf(
"[Client] Message received OK!:\n");
111 printf(
" MSG Type: %i\n", msg.
type);
113 " MSG Length: %u bytes\n", (
unsigned int)msg.
content.size());
114 printf(
"[Client] Parsing payload...\n");
119 #ifdef SOCKET_TEST_VERBOSE 120 printf(
"[Client] Received payload: %s\n", p_rx.
asString().c_str());
121 printf(
"[Client] tx payload: %s\n",
p_tx.
asString().c_str());
122 printf(
"[Client] Done!!\n");
128 #ifdef SOCKET_TEST_VERBOSE 129 printf(
"[Client] Finish\n");
132 catch (std::exception& e)
134 cerr << e.what() << endl;
138 cerr <<
"[thread_client] Runtime error!" << endl;
148 using namespace std::chrono_literals;
151 std::this_thread::sleep_for(100ms);
154 std::this_thread::sleep_for(1000ms);
bool sendMessage(const MESSAGE &outMsg, const int timeout_ms=-1)
Send a message through the TCP stream.
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
void changeCurrentThreadPriority(TThreadPriority priority)
Change the priority of the current thread - for Windows, see also changeCurrentProcessPriority() ...
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.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
std::unique_ptr< CClientTCPSocket > accept(int timeout_ms=-1)
Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represen...
A TCP socket that can be wait for client connections to enter.
bool sockets_test_passed_ok
const mrpt::poses::CPose3D p_tx(1.0, 2.0, 3.0, 0.2, 0.4, 0.6)
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[x y z yaw pitch roll]"...
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
void deserializeIntoExistingObject(CSerializable *obj)
A method that parse the data in the message into an existing object.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
Serial and networking devices and utilities.
void serializeObject(const CSerializable *obj)
A method for serializing a MRPT's object into the content.
Win32: THREAD_PRIORITY_BELOW_NORMAL.
#define SOCKET_TEST_VERBOSE