xtd 0.2.0
tcp_client_ip_v6.cpp

Shows how to use xtd::net::sockets::tcp_client class.

#include <xtd/io/stream_reader>
#include <xtd/net/sockets/tcp_client>
#include <xtd/net/sockets/tcp_listener>
#include <xtd/threading/thread>
#include <xtd/console>
using namespace xtd;
using namespace xtd::io;
using namespace xtd::net;
using namespace xtd::net::sockets;
using namespace xtd::threading;
auto main() -> int {
auto terminate_app = false;
auto server = thread {[&] {
listener.start();
auto stream = listener.accept_tcp_client().get_stream();
auto reader = stream_reader {stream};
while (!terminate_app)
if (stream.data_available()) console::write_line(reader.read_line());
}};
auto client = thread {[&] {
auto stream = client.get_stream();
auto writer = stream_writer {stream};
auto counter = 0;
while (!terminate_app) {
writer.write_line("counter={}", ++counter);
thread::sleep(50_ms);
}
}};
server.start();
client.start();
terminate_app = true;
server.join();
client.join();
}
// This code produces the following output :
//
// counter=1
// counter=2
// counter=3
// counter=4
// counter=5
// ...
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Implements a xtd::io::text_reader that reads characters from a byte stream.
Definition stream_reader.hpp:28
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.hpp:28
Provides a generic view of a sequence of bytes. This is an abstract class.
Definition stream.hpp:40
static const ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.hpp:58
static const ip_address ip_v6_any
The Socket::Bind method uses the cIPv6Any field to indicate that a Socket must listen for client acti...
Definition ip_address.hpp:55
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.hpp:28
Provides client connections for TCP network services.
Definition tcp_client.hpp:48
void connect(const xtd::net::ip_end_point &remote_end_point)
Connects the client to a remote TCP host using the specified remote network endpoint.
Listens for connections from TCP network clients.
Definition tcp_listener.hpp:40
void start()
xtd::net::sockets::tcp_listener::starts listening for incoming connection requests.
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:45
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
void start()
Causes the operating system to change the state of the current instance to xtd::threading::thread_sta...
@ inter_network_v6
Address for IP version 6.
Definition address_family.hpp:82
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.hpp:16
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.hpp:10
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8