Go to the documentation of this file.
32 #ifdef SOCKET_TEST_VERBOSE
33 printf(
"[Server] Started\n");
37 15000,
"127.0.0.1", 10,
44 std::unique_ptr<CClientTCPSocket> client = server.
accept(2000);
48 #ifdef SOCKET_TEST_VERBOSE
49 printf(
"[Server] Connection accepted\n");
58 std::this_thread::sleep_for(50ms);
61 #ifdef SOCKET_TEST_VERBOSE
62 printf(
"[Server] Finish\n");
65 catch (std::exception& e)
67 cerr << e.what() << endl;
71 printf(
"[thread_server] Runtime error!\n");
84 #ifdef SOCKET_TEST_VERBOSE
85 printf(
"[Client] Connecting\n");
88 sock.
connect(
"127.0.0.1", 15000);
90 #ifdef SOCKET_TEST_VERBOSE
91 printf(
"[Client] Connected. Waiting for a message...\n");
102 printf(
"[Client] Error receiving message!!\n");
106 #ifdef SOCKET_TEST_VERBOSE
107 printf(
"[Client] Message received OK!:\n");
108 printf(
" MSG Type: %i\n", msg.
type);
110 " MSG Length: %u bytes\n", (
unsigned int)msg.
content.size());
111 printf(
"[Client] Parsing payload...\n");
116 #ifdef SOCKET_TEST_VERBOSE
117 printf(
"[Client] Received payload: %s\n", p_rx.
asString().c_str());
118 printf(
"[Client] tx payload: %s\n",
p_tx.
asString().c_str());
119 printf(
"[Client] Done!!\n");
125 #ifdef SOCKET_TEST_VERBOSE
126 printf(
"[Client] Finish\n");
129 catch (std::exception& e)
131 cerr << e.what() << endl;
135 cerr <<
"[thread_client] Runtime error!" << endl;
145 using namespace std::chrono_literals;
148 std::this_thread::sleep_for(100ms);
151 std::this_thread::sleep_for(1000ms);
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
A TCP socket that can be wait for client connections to enter.
std::unique_ptr< CClientTCPSocket > accept(int timeout_ms=-1)
Waits for an incoming connection (indefinitely, or with a given timeout) The returned object represen...
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.
Serial and networking devices and utilities.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
bool sendMessage(const MESSAGE &outMsg, const int timeout_ms=-1)
Send a message through the TCP stream.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
const mrpt::poses::CPose3D p_tx(1.0, 2.0, 3.0, 0.2, 0.4, 0.6)
#define SOCKET_TEST_VERBOSE
bool sockets_test_passed_ok
void deserializeIntoExistingObject(CSerializable *obj)
A method that parse the data in the message into an existing object.
void serializeObject(const CSerializable *obj)
A method for serializing a MRPT's object into the content.
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[x y z yaw pitch roll]",...
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 | |