#include <tcp_listener.h>
Listens for connections from TCP network clients.
- Inheritance
- xtd::object → xtd::net::sockets::tcp_listener
- Namespace
- xtd::net::sockets
- Library
- xtd.core
- Note
- The xtd::net::sockets::tcp_listener::stop method does not close any accepted connections. You are responsible for closing these separately.
- Examples
- The following example shows how to use IPv4 xtd::net::sockets::tcp_listener class with use xtd::net::sockets::tcp_client, xtd::net::sockets::network_stream, xtd::net::sockets::socket, xtd::io::stream_reader and xtd::io::stream_writer classes.
#include <xtd/xtd>
using namespace std;
using namespace std::literals;
auto main()->int {
auto terminate_app = false;
listener.start();
auto stream = listener.accept_tcp_client().get_stream();
while (!terminate_app)
if (
stream.data_available()) console::write_line(reader.read_line());
});
thread client([&] {
auto counter = 1;
while (!terminate_app) {
writer.write_line(ustring::format("counter={}", counter++));
this_thread::sleep_for(50ms);
}
});
terminate_app = true;
client.join();
}
- Examples
- The following example shows how to use IPv6 xtd::net::sockets::tcp_listener class with use xtd::net::sockets::tcp_client, xtd::net::sockets::network_stream, xtd::net::sockets::socket, xtd::io::stream_reader and xtd::io::stream_writer classes.
#include <xtd/xtd>
using namespace std;
using namespace std::literals;
auto main()->int {
auto terminate_app = false;
listener.start();
auto stream = listener.accept_tcp_client().get_stream();
while (!terminate_app)
if (
stream.data_available()) console::write_line(reader.read_line());
});
thread client([&] {
auto counter = 1;
while (!terminate_app) {
writer.write_line(ustring::format("counter={}", counter++));
this_thread::sleep_for(50ms);
}
});
terminate_app = true;
client.join();
}
- Examples:
- tcp_client_ip_v6.cpp.
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Gets the type of the current instance. More...
|
|
virtual xtd::ustring | to_string () const noexcept |
| Returns a sxd::ustring that represents the current object. More...
|
|
virtual bool | equals (const tcp_listener &) const noexcept=0 |
| Indicates whether the current object is equal to another object of the same type. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|
◆ tcp_listener() [1/2]
Initializes a new instance of the xtd::net::sockets::tcp_listener class with the specified local endpoint.
- Parameters
-
- Note
- The 0 for local port functionality is not available.
◆ tcp_listener() [2/2]
Initializes a new instance of the xtd::net::sockets::tcp_listener class that listens for incoming connection attempts on the specified local IP address and port number.
- Parameters
-
- Note
- The 0 for local port functionality is not available.
◆ accept_socket()
◆ accept_tcp_client()
◆ active()
bool xtd::net::sockets::tcp_listener::active |
( |
| ) |
const |
|
protectednoexcept |
◆ begin_accept_socket()
◆ begin_accept_tcp_client()
Begins an asynchronous operation to accept an incoming connection attempt.
- Parameters
-
async_result | An xtd::async_callback delegate that references the method to invoke when the operation is complete. |
state | A user-defined object containing information about the accept operation. This object is passed to the callback delegate when the operation is complete. |
- Returns
- An xtd::iasync_result that references the asynchronous creation of the xtd::net::sockets::tcp_client.
- Exceptions
-
- Note
- If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
◆ create()
◆ end_accept_socket()
◆ end_accept_tcp_client()
Asynchronously accepts an incoming connection attempt and creates a new xtd::net::sockets::tcp_client to handle remote host communication.
- Parameters
-
async_result | An xtd::iasync_result returned by a call to the xtd::net::sockets::tcp_listener::begin_accept_tcp_client(xtd::async_callback, std::any) method. |
state | A user-defined object containing information about the accept operation. This object is passed to the callback delegate when the operation is complete. |
- Returns
- An xtd::iasync_result that references the asynchronous creation of the xtd::net::sockets::tcp_client.
- Exceptions
-
- Note
- If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
◆ exclusive_address_use() [1/2]
bool xtd::net::sockets::tcp_listener::exclusive_address_use |
( |
| ) |
const |
◆ exclusive_address_use() [2/2]
tcp_listener& xtd::net::sockets::tcp_listener::exclusive_address_use |
( |
bool |
value | ) |
|
◆ local_end_point()
◆ pending()
bool xtd::net::sockets::tcp_listener::pending |
( |
| ) |
|
Determines if there are pending connection requests.
- Returns
- true if connections are pending; otherwise, false.
- Exceptions
-
◆ server()
◆ start() [1/2]
void xtd::net::sockets::tcp_listener::start |
( |
| ) |
|
◆ start() [2/2]
void xtd::net::sockets::tcp_listener::start |
( |
size_t |
backlog | ) |
|
xtd::net::sockets::tcp_listener::starts listening for incoming connection requests with a maximum number of pending connection.
- Parameters
-
backlog | The maximum length of the pending connections queue. |
- Exceptions
-
- Note
- If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
◆ stop()
void xtd::net::sockets::tcp_listener::stop |
( |
| ) |
|
The documentation for this class was generated from the following file: