ASIO is a rather large and sprawling affair, made more complicated by having 11 ways of doing the same thing, in both synchronous and asynchronous fashion.
This pair of examples shows, I hope, the absolute minimum amount of code to get a working SSL connection between a client and server, the latter acting as an echo service.
ASIO itself is a header only affair (+1) and is contained in a submodule. Hence once the repo is cloned, do this:
cd asiotest
git submodule init
git submodule update --recursive
For Windows/Visual Studio, setup is critical and extremely tedious unless vcpkg is used.
For this sort of gig I like everything to be contained in a single binary, hence static linkage for both runtime and support libraries. The VS2022 project files are set up accordingly. See the vcpkg tab in the solution explorer.
Step by step:
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
vcpkg integrate install
vcpkg install asio:x64-windows-static
vcpkg install openssl:x64-windows-static
- Open asiotest.sln
- Rebuild.
Ensure libraries are installed:
sudo apt install libasio-dev libssl-dev libczmq-dev libsodium-dev
make -C ./server
make -C ./client
- Run
makcert.cmd
(makcert.sh
on Linux/MacOS) to generate required (self-signed) certificates. This is a once-off affair and may take some time. - Run the server:
server 3456
- Run the client:
client localhost 3456
- Send simple text messages,
quit
to shutdown client.
If you run the client on a different host, you will need to copy certs/rootca.pem
which contain the relevant public keys.