Skip to content

Cross-platform networking library.

License

Notifications You must be signed in to change notification settings

dvsku/libnetwrk

Repository files navigation

libnetwrk

Cross-platform networking library.


About

Based heavily on javidx9's work with networking. Relies on embedded ASIO 1.14.0 library.
Recommended for use on small personal projects as it's not heavily tested.

Requirements

  • c++20 or later compiler

Usage

  • Copy libnetwrk directory to your project
  • Include libnetwrk directory in your project
  • Include libnetwrk.hpp

Limitations

  • currently only supports TCP
  • libnetwrk uses a simple binary serializer by default, so cross-platform compatibility is not guaranteed. You can implement your own serializer by looking at bin_serialize.hpp as an example.

Usage examples

Making a custom object serializeable

template<typename T>
void serialize(libnetwrk::buffer<T>& buffer) const {
    ...
}

template<typename T>
void deserialize(libnetwrk::buffer<T>& buffer) {
    ...
}

To make an object serializable you need to add and implement these functions.

#include "libnetwrk.hpp"

struct object {
    std::string string_1;
  
    template<typename T>
    void serialize(libnetwrk::buffer<T>& buffer) const {
        buffer << string_1;
    }
  
    template<typename T>
    void deserialize(libnetwrk::buffer<T>& buffer) {
        buffer >> string_1;
    }
}

struct derived_object : object {
    std::string string_2;
  
    template<typename T>
    void serialize(libnetwrk::buffer<T>& buffer) const {
        object::serialize(buffer);
        buffer << string_2;
    }
  
    template<typename T>
    void deserialize(libnetwrk::buffer<T>& buffer) {
        object::deserialize(buffer);
        buffer >> string_2;
    }
}

Changes

  • 05 Jan 2024
    • Changed custom object serialization. Previous serialization requried a separate object for each serializer type.