34 #ifdef SOCKET_TEST_VERBOSE 35 printf(
"[Server] Started\n");
39 15000,
"127.0.0.1", 10,
46 std::unique_ptr<CClientTCPSocket> client = server.
accept(5000);
50 #ifdef SOCKET_TEST_VERBOSE 51 printf(
"[Server] Connection accepted\n");
60 std::this_thread::sleep_for(2000ms);
63 #ifdef SOCKET_TEST_VERBOSE 64 printf(
"[Server] Finish\n");
67 catch (
const std::exception& e)
69 cerr << e.what() << endl;
73 printf(
"[thread_server] Runtime error!\n");
88 #ifdef SOCKET_TEST_VERBOSE 89 printf(
"[Client] Connecting\n");
92 sock.
connect(
"127.0.0.1", 15000);
94 #ifdef SOCKET_TEST_VERBOSE 95 printf(
"[Client] Connected. Waiting for a message...\n");
106 printf(
"[Client] Error receiving message!!\n");
110 #ifdef SOCKET_TEST_VERBOSE 111 printf(
"[Client] Message received OK!:\n");
112 printf(
" MSG Type: %i\n", msg.
type);
114 " MSG Length: %u bytes\n", (
unsigned int)msg.
content.size());
115 printf(
"[Client] Parsing payload...\n");
120 #ifdef SOCKET_TEST_VERBOSE 121 printf(
"[Client] Received payload: %s\n", p_rx.
asString().c_str());
122 printf(
"[Client] tx payload: %s\n",
p_tx.
asString().c_str());
123 printf(
"[Client] Done!!\n");
129 #ifdef SOCKET_TEST_VERBOSE 130 printf(
"[Client] Finish\n");
133 catch (
const std::exception& e)
135 cerr << e.what() << endl;
139 cerr <<
"[thread_client] Runtime error!" << endl;
148 using namespace std::chrono_literals;
151 std::this_thread::sleep_for(20ms);
154 std::this_thread::sleep_for(200ms);
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