Skip to content

Commit ebb72c4

Browse files
Update README.md
1 parent e8132a2 commit ebb72c4

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

README.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,43 @@ struct : TcpServer::Observer {
1414
void onConnectionAccepted(int id) {
1515
std::cout << "New client connected with id " << id << std::endl;
1616
};
17+
void onConnectionClosed(int id) {
18+
std::cout << "Client disconnected with id " << id << std::endl;
19+
};
1720
void onReceived(int id, const char* data, size_t size) {
1821
std::cout << "Data received from client with id " << id << ": ";
1922
std::cout.write(data, size);
2023
std::cout << std::endl;
2124
}
22-
void onConnectionClosed(int id) {
23-
std::cout << "Client disconnected with id " << id << std::endl;
24-
};
2525
} observer;
2626

2727
boost::asio::io_context context;
2828
std::thread thread{[&context]() { context.run(); }};
2929

3030
TcpServer server{context, observer};
31-
32-
constexpr uint16_t port{1234};
33-
const auto protocol{boost::asio::ip::tcp::v4()};
34-
server.listen(protocol, port);
35-
31+
server.listen(boost::asio::ip::tcp::v4(), 1234);
3632
server.startAcceptingConnections();
3733

3834
```
3935
### Client
4036
```cpp
4137
struct : TcpClient::Observer {
4238
void onConnected() { std::cout << "Client was connected" << std::endl; };
39+
void onDisconnected() {
40+
std::cout << "Client was disconnected " << std::endl;
41+
};
4342
void onReceived(const char* data, size_t size) {
4443
std::cout << "Data received: ";
4544
std::cout.write(data, size);
4645
std::cout << std::endl;
4746
}
48-
void onDisconnected() {
49-
std::cout << "Client was disconnected " << std::endl;
50-
};
5147
} observer;
5248
5349
boost::asio::io_context context;
5450
std::thread thread{[&context]() { context.run(); }};
5551
5652
TcpClient client{context, observer};
57-
58-
constexpr uint16_t port{1234};
59-
auto address{boost::asio::ip::address::from_string("127.0.0.1")};
60-
client.connect({address, port});
53+
client.connect({boost::asio::ip::address::from_string("127.0.0.1"), 1234});
6154
```
6255
## Build
6356
- Install dependencies.

0 commit comments

Comments
 (0)