GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - PolymorphEngine/NetworkLibrary: A simple library to transfer DTOs over network

BranchesTags
Open more actions menu

Latest commit

 

History

146 Commits
146 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
cmake
cmake
 
 
docs
docs
 
 
examples
examples
 
 
include/polymorph/network
include/polymorph/network
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CMakeLists.txt
CMakeLists.txt
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
FindPolymorphNetworkLibrary.cmake
FindPolymorphNetworkLibrary.cmake
 
 
LICENSE
LICENSE
 
 
readme.md
readme.md
 
 

Repository files navigation

Polymorph Network Library (PNL)

A simple library to use in your networked projects.

  • Support for TCP and UDP
  • Support for IPv4
  • Safe and easy to use
  • Cross-platform
  • Tested with GCC and Visual Studio
  • Tested with Valgrind

⚙ How does it work?

The library has a simple API, which is divided into two parts: the Client and the Server. They both have pretty much the same API, but some methods are exclusive.
The client and server are designed to exchange Packets.

What is a packet ?

A Packet just a simple structure containing base information and a payload. The payload can be any type of data.
Since the data transferred over the network needs to be converted to a byte array, the library provides a SerializerTrait trait to do that. Where the library deliver all its power is in the SerializerTrait trait. Indeed, this trait can be specialized to serialize user defined types.

As long as you provide a serializer/deserializer for your type, you can send it over the network.

What is the SessionStore ?

The SessionStore is a simple class that stores the sessions of the clients connected to the server. This SessionStore can be shared across a UDP and a TCP server. This allows the clients to keep their session between the two servers.
To do so, it generates an authentication token for each client. This token is then sent to the client and is used to identify the client on the other server and safely attribute the same session.

What is an OpId ?

The OpId is a simple identifier for a packet. It is used to identify the packet type and call the appropriate callback after casting the received byte stream into a header + payload form. A DTO type can have multiple OpId associated with it. This allows you to have multiple callbacks for the same type.
Example:

struct SampleDto {
    static constexpr OpId opIdXPos = 0;
    static constexpr OpId opIdYPos = 1;
    int value;
};

// Registering a callback for the X position
client.registerReceiveHandler<SampleDto>(SampleDto::opIdXPos, [](const PacketHeader &header, const SampleDto &payload) {
    std::cout << "Client received X position: " << payload.value << std::endl;
    return true;
});
client.registerReceiveHandler<SampleDto>(SampleDto::opIdYPos, [](const PacketHeader &header, const SampleDto &payload) {
    std::cout << "Client received Y position: " << payload.value << std::endl;
    return true;
});

📁 Add the library to your project

There is two ways to add the library to your project:

  • Add the library as a submodule
  • Use the CMake FetchContent module

Add the library as a submodule

git submodule add https://github.com/PolymorphEngine/NetworkLibrary.git

You will then need to compile it or, if you are using CMake, add it to your project.

add_subdirectory(NetworkLibrary)

Use the CMake FetchContent module

You will need to download the FinderPolymorphNetworkLibrary.cmake (also available in releases)

include(path/to/FindPolymorphNetworkLibrary.cmake)

Then, you will have to reload the CMake cache and the library will be downloaded and the headers will be available.

🔨 How to use the lib ?

How to create a server/client ?

See the TCP and UDP to see how to use the library in your project.

How to create a custom DTO ?

See the DTO page to see how to define your DTOs for your protocol.

About

A simple library to transfer DTOs over network

Topics

asionetworkpolymorph

Resources

Readme
GPL-3.0 license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.