C++ port of the famous networking library LiteNetLib written in C#
As of now, library can be built with MSVC on Windows and with GCC on Linux. OS X support is planned in the future releases.
In order to build and run example project use following commands in Powershell for Windows:
git clone [email protected]:Revan600/LiteNetLibPP.git
cd LiteNetLibPP
mkdir build
cd build
cmake ../
cmake --build .
.Debuglnl_example_server.exe
.Debuglnl_example_client.exe
Or in bash for Linux:
git clone [email protected]:Revan600/LiteNetLibPP.git
cd LiteNetLibPP
mkdir build
cd build
cmake ../
make
./lnl_example_server
./lnl_example_client
After that you should be able to connect to the test server via localhost:4499 (or via your public IP)
All features of LiteNetLib implemented except of those:
A simple ping-pong with 1000 clients (server benchmark): No packet or connection drops were observed during the tests (but I'm sure there would be some bugs, so feel free to fill the issue)
Here's simple client and server example which was used in the performance tests. More examples could be found here
#include <lnl/lnl.h>
class my_listener : public lnl::net_event_listener {
public:
void on_network_receive(std::shared_ptr<lnl::net_peer>& peer, lnl::net_data_reader& reader, uint8_t channelNumber,
lnl::DELIVERY_METHOD deliveryMethod) override {
static lnl::net_data_writer writer;
int32_t value;
if (!reader.try_read(value)) {
printf("cannot read valuen");
return;
}
writer.reset();
value++;
writer.write(value);
peer->send(writer, lnl::DELIVERY_METHOD::RELIABLE_ORDERED);
}
void on_connection_request(std::shared_ptr<lnl::net_connection_request>& request) override {
request->accept();
}
};
int main() {
lnl::initialize();
my_listener listener;
lnl::net_manager server(&listener);
server.start(4499);
while (server.is_running()) {
server.poll_events();
}
return 0;
}
#include <lnl/lnl.h>
class my_listener : public lnl::net_event_listener {
public:
void on_network_receive(std::shared_ptr<lnl::net_peer>& peer, lnl::net_data_reader& reader, uint8_t channelNumber,
lnl::DELIVERY_METHOD deliveryMethod) override {
static lnl::net_data_writer writer;
int32_t value;
if (!reader.try_read(value)) {
printf("cannot read valuen");
return;
}
writer.reset();
printf("%in", value);
value++;
writer.write(value);
peer->send(writer, lnl::DELIVERY_METHOD::RELIABLE_ORDERED);
}
void on_connection_request(std::shared_ptr<lnl::net_connection_request>& request) override {
request->accept();
}
};
int main() {
lnl::initialize();
my_listener listener;
lnl::net_manager client(&listener);
lnl::net_address address("localhost", 4499);
lnl::net_data_writer writer;
client.start();
client.connect(address, writer);
while (client.is_running()) {
client.poll_events();
}
return 0;
}