README.md
1
2# Asio chat client and server examples
3
4(See the README.md file in the upper level 'examples' directory for more information about examples.)
5
6The application aims to demonstrate a simple use of Asio library in different modes.
7In project settings it could be configured to run either a Asio chat server, a Asio chat client, or both.
8
9## How to use example
10
11The example is configured by default as an Asio chat client.
12
13Note that the example uses string representation of IP addresses and ports.
14
15You can find the upstream asio chat implementation [here] https://github.com/chriskohlhoff/asio/tree/master/asio/src/examples/cpp11/chat
16
17### Asio Client
18
19In the client mode, the example connects to the configured address, sends the message, which was inserted as an input in the terminal, and receives a response.
20
21### Asio Server
22
23In the server mode, Asio chat server with a specified port number is created and being polled till a connection request from the client arrives.
24Chat server echoes a message (received from any client) to all connected clients.
25
26## Configure the project
27
28```
29idf.py menuconfig
30```
31
32Set following parameters under Example Configuration Options:
33
34* Set `EXAMPLE_CHAT_SERVER` to use the example as an ASIO chat server
35 * Configure `EXAMPLE_CHAT_SERVER_BIND_PORT` to the port number.
36
37* Set `EXAMPLE_CHAT_CLIENT` to use the example as an ASIO chat client
38 * Configure `EXAMPLE_CHAT_CLIENT_CONNECT_ADDRESS` to a string representation of the address to connect the client to.
39 * Configure `EXAMPLE_CHAT_CLIENT_CONNECT_PORT` to the port number.
40
41* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more d etails.
42
43## Running the example in server mode
44
45- Configure the example according "Configure the project" section.
46- Run `idf.py -p PORT flash monitor` to build and upload the example to your board and connect to it's serial terminal.
47- Wait for the board to connect to WiFi or Ethernet (note the IP address).
48- Connect to the server using multiple clients, for example using any option below.
49 - build and run asio chat client on your host machine
50 - run chat_client asio example on ESP platform
51 - since chat messages consists of ASCII size and message, it is possible to
52 netcat `nc IP PORT` and type for example ` 4ABC<CR>` to transmit 'ABC\n'
53
54## Running the example in client mode
55
56- Configure the example according "Configure the project" section.
57- Start chat server either on host machine or as another ESP device running chat_server example.
58- Run `idf.py -p PORT flash monitor` to build and upload the example to your board and connect to it's serial terminal.
59- Wait for the board to connect to WiFi or Ethernet.
60- Receive and send messages to/from other clients on stdin/stdout via serial terminal.
61
62See the README.md file in the upper level 'examples' directory for more information about examples.
63