In order to build the code you need CMake version 3.0 or higher on your system. Build as follows:
$
git clone https://github.com/vrtql/websockets.git$
cd websockets$
cmake .$
make$
sudo make install
Unit tests are located in test
. As a basic test of
operation, you can run the test_websockets
test. To run it,
first start the server as follows:
$
cd test$
./server
This is just a simple echo server example from the Mongoose project, used for
testing. There is simple Mongoose-based client program in the
test
directory as well called client
which can be used to test general connectivity. After the server is started, run
test_websockets
to see that everything is working:
$
./test_websockets
TEST 1/4 test:send_receive
+----------------------------------------------------+
| Frame Sent |
+----------------------------------------------------+
header: 6 bytes
fin: 1
opcode: 1
mask: 1 (0xb95d570f)
payload: 7 bytes
da 32 39 7b dc 33 23
------------------------------------------------------
+----------------------------------------------------+
| Frame Received |
+----------------------------------------------------+
header: 2 bytes
fin: 1
opcode: 1
mask: 0 (0x00000000)
payload: 7 bytes
.
.
.
This will connect to the server and run various send/receive tests dumping the frames sent to and received from the server to the console.
You must have the requisite MinGW compiler and tools installed on your system. For Debian/Devuan you would install these as follows:
$
sudo apt-get install mingw-w64 mingw-w64-tools mingw-w64-common \
g++-mingw-w64-x86-64 mingw-w64-x86-64-dev
You will need to have OpenSSL for Windows on your system as well. If you
don't have it you can build as follows. First download the version you want to
build. Here we will use openssl-1.1.1u.tar.gz
as an
example. Create the install directory you intend to put OpenSSL in. For example:
$
mkdir ~/mingw
Build OpenSSL. You want to ensure you set the --prefix
to the
directory you specified above. This is where OpenSSL will install to.
$
cd /tmp$
tar xzvf openssl-1.1.1u.tar.gz$
cd openssl-1.1.1u$
./Configure --cross-compile-prefix=x86_64-w64-mingw32- \ --prefix=~/mingw shared mingw64 no-tests$
make$
make DESTDIR=~/mingw install
Now within the websockets
project. Modify the
CMAKE_FIND_ROOT_PATH
in the
config/windows-toolchain.cmake
file to point to where you
installed OpenSSL. The line to modify is shown in bold below:
set(CMAKE_SYSTEM_NAME Windows) set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) # cross compilers to use for C, C++ set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) # Set to where you have it installed set(CMAKE_FIND_ROOT_PATH "/home/bubba/mingw/openssl") # modify default behavior of FIND_XXX() commands set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
In this example it would be
~/mingw/openssl
(you might want to use full path). Then
invoke CMake as follows:
$
cmake -DCMAKE_TOOLCHAIN_FILE=config/windows-toolchain.cmake
Then build as normal:
$
make