-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <cstring> | ||
#include <iostream> | ||
#include <thread> | ||
|
||
#include <cubos/core/log.hpp> | ||
/// [Import header] | ||
#include <cubos/core/net/tcp_socket.hpp> | ||
/// [Import header] | ||
#include <cubos/core/reflection/external/cstring.hpp> | ||
#include <cubos/core/reflection/external/primitives.hpp> | ||
|
||
using cubos::core::net::Address; | ||
using cubos::core::net::TcpSocket; | ||
|
||
/// [Define constants] | ||
#define SERVER_ADDRESS Address::LocalHost | ||
#define SERVER_PORT 8080 | ||
/// [Define constants] | ||
|
||
/// [Client function] | ||
void runClient() | ||
{ | ||
TcpSocket socket; | ||
CUBOS_ASSERT(socket.connect(SERVER_ADDRESS, SERVER_PORT, 0), "Failed to connect to TCP server"); | ||
|
||
CUBOS_INFO("TCP client connected at port {}", SERVER_PORT); | ||
|
||
// send message | ||
std::string msg = "ping"; | ||
CUBOS_ASSERT(socket.send(msg), "Failed to send data via TCP"); | ||
|
||
// receive message | ||
char buffer[1024]; | ||
std::size_t received; | ||
Address senderAddress; | ||
CUBOS_ASSERT(socket.receive(buffer, sizeof(buffer), received), "Failed to receive data via TCP"); | ||
|
||
CUBOS_INFO("Received via TCP: {}", buffer); | ||
} | ||
/// [Client function] | ||
|
||
int main() | ||
{ | ||
CUBOS_TODO("listener part"); | ||
} |