LiteNetLib
LiteNetLib copied to clipboard
Example Usage
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:
- Godot engine mono version 3.3.2
- OpenGL 2.1 / OpenGL ES 2.0 compatible hardware
- MSBuild (from Visual Studio Build Tools or the Mono SDK)
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:
- 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.
- This example give you basic writing and reading using LiteNetLib.
- 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.
- 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.