connecting a socket

This commit is contained in:
Антон 2024-03-29 07:04:50 +03:00
parent a378205f48
commit 810575f37e
3 changed files with 37 additions and 12 deletions

View File

@ -19,8 +19,6 @@ endif ()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
configure_file(config.json ${CMAKE_BUILD_RPATH} config.json COPYONLY)
add_executable(client_endpoint
endpoint.cpp
src/sdk.h)
@ -50,3 +48,8 @@ add_executable(binding_socket_to_an_endpoint
binding_socket_to_an_endpoint.cpp
src/sdk.h)
target_link_libraries(binding_socket_to_an_endpoint PRIVATE Threads::Threads)
add_executable(connecting_a_socket
connecting_a_socket.cpp
src/sdk.h)
target_link_libraries(connecting_a_socket PRIVATE Threads::Threads)

View File

@ -1,10 +0,0 @@
{
"maps": {
"map1": {
"a": 123
},
"map2": {
"b": 456
}
}
}

View File

@ -0,0 +1,32 @@
#include "src/sdk.h"
//
#include <boost/asio.hpp>
#include <iostream>
using namespace boost;
namespace sys = boost::system;
namespace net = boost::asio;
using namespace std;
int main()
{
string raw_ip_address = "127.0.0.1"s;
uint16_t port = 3333;
try
{
net::ip::tcp::endpoint ep(net::ip::address::from_string(raw_ip_address), port);
net::io_context io_context;
net::ip::tcp::socket socket(io_context, ep.protocol());
socket.connect(ep);
}
catch (const sys::system_error& e)
{
cout << "Error: "s << e.what() << endl;
return e.code().value();
}
return EXIT_SUCCESS;
}