This library provides universal cross-platform network sockets implementation. Supports Windows (recommended MinGW UCRT64 env., MSVC also supported), and any other OS that provides POSIX socket implementation. Also this library supports both static & dynamic linking and building (if set CMake BUILD_SHARED_LIBS to ON).
Caution
This library isn't yet completely thread-safe. Beware when using this library in multithread applications and programs.
Caution
Note, that now supported only little-endian CPU arch.-es, because host to network byte order convertion macroses hardcoded in header(-s) only for little-endian CPU arch.-es.
- Windows (fully x86-64, theoretically x86-32 (IA-32), "ARM64", "ARM32") with WinSock 2.2 support (but you can change WinSock version through initialization options struct when you initializating the library).
- any POSIX-compatible OS, such as Linux (inclues Android; library tested in Termux), BSD-s and other (arch.-es same as for Windows).
Requirements: Visual Studio, CMake
- Clone this repo and open it folder in Visual Studio.
- Visual Studio must generate MSBuild script through CMake automaticly. Just wait for it.
- Build library and tests through Viusal Studio GUI, using hotkey (Ctrl + Shift + B by default) or terminal.
Requirements: MSYS2 UCRT64, MinGW UCRT64, make, CMake.
- Run MSYS2 UCRT64 environment (recommended). Install all requirements if you haven't it.
- Clone this repo and go to repository root folder.
- Create folder
build. Go to this catalog. - Run
cmake -S .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PATH=$MSYSTEM_PREFIX. Wait for generating Makefile. - Run
mingw32-makeand wait for building library.
Requirements: GCC, make, CMake
- Install all requirements if you haven't it.
- Clone this repo and go to repository root folder.
- Create folder
build. Go to this catalog. - Run
cmake -S ... Wait for generating Makefile. - Run
makeand wait for building library.
Just run mingw32-make install. Library will be installed to your MSYS2 system path (specified in -DCMAKE_INSTALL_PATH CMake option; /ucrt64 in this example).
Also just run sudo make install. Library will be installed to your system.
Warning
Manual linking is not recommended library usage way. Please use CMake for correct linking with library.
Include <libsocket.h> header where you need to use this library. That link your executable with library by adding flag to command line -lsocket. On Windows you already need to link you executable with WinSock2 library, so just add flag -lws2_32 command line. If you use static version of this library, please specify definition LIBSOCKET_STATIC when you compile file, where included libsocket header.
If you using CMake in your project, add libsocket by same method or with using find_package:
find_package(libsocket REQUIRED)
target_link_libraries(<target> PRIVATE libsocket::socket)This will fully automatily setup libsocket for your project. By default CMake will use static version of libsocket, so if you want to use dynamic version of this library, set BUILD_SHARED_LIBS flag in your CMake config command prompt to ON.
Tests are available in /tests/ folder in the root of repo. You can also use they as examples. Also in /tests/ folder available README.md file with (short) description of every available test.