LiteNetLib icon indicating copy to clipboard operation
LiteNetLib copied to clipboard

Example Usage

Open nongvantinh opened this issue 4 years ago • 0 comments

I spend some time trying to understand LiteNetLib library version 0.9.5.1 by experiment it with Godot engine mono version 3.3.2. And want to share my knowledge about this library to help someone get started quickly.

Requiments:

Getting started

  • First open project and click build solution in the top right corner.
  • Open the Main scene and uncheck Server Build
  • Now go to: Project -> Export -> add export preset for your desktop and click Export Project
  • Return to the editor and check Server Build then click Play or F5
  • After the server has been running, open your client build and run it.

Results:

  1. client connect to server.zip
  • This example provider-client/server model.
  • On application start, client connect to the server and the server print out a message when the client is trying to connect to.
  1. server accept client and send client a message.zip
  • This example give you basic writing and reading using LiteNetLib.
  1. Server send client serializable packet.zip
  • This example show you the way LiteNetLib serialize packets.
  • On connected, Server send a snapshot packet to client.
  • On client side, whenever client press "space" key it send a "ClientInputMessage" to server to demonstrate sending message from client side.
  1. Test memory leak.zip
  • In the past, I tried yojimbo library (C# version, not C++), and it causes memory leak, This test make sure lite net lib pass the test about memory leak.

Remark:

  • There is another way to serialize packet, by define your own static Serialize/Deserialize function, and send by using method 2, but I see it redundant, so I leave it alone.
  • You can only use one method in 3 ways that I give above to serialize your packet.
  • For games, method 3 is definitely the way to go.

I will add more example usage by adding more future base on the original project I give above.

nongvantinh avatar Aug 19 '21 13:08 nongvantinh