ENetUnityMobile
ENetUnityMobile copied to clipboard
I have a few questions and would like your help. About Server.
Hello, I am using enet for the first time, and I am not very good at programming technology. I have a few questions and would like your help.
- I see the received code on the server. I want to know how to parse the string content sent by the client. What should I do?
- The sample code returned by the server is a broadcast message. If I want to send it to a single client, how should I write the code?
Ask for your help, thank you sincerely!
Hey there!
- In general I would not suggest to parse strings, but rather use a byte based format, that does not rely on strings. Those result in smaller message sizes and faster serialization/deserialization. A good example is MessagePack-CSharp. Also note, that all the code of the server currently runs in a single thread. Normally you would want to have one thread handling all the IO and other threads handling the game loop and processing the messages. Therefore you would need something like concurrent queues or ringbuffers to communicate between the IO thread and the other threads. Also note, that ENet is not threadsafe and therefore all ntework IO has to happen on one thread.
- In my example you would need to call
netEvent.Peer.Send(netEvent.ChannelID, ref packet), for documentation on how to use ENet see https://github.com/nxrighthere/ENet-CSharp#create-and-send-a-new-packet
In general: Setting up ENet is a lot more low level than for other solutions. Even though it is very performant, you can lose all of that, if you don't know what you are doing. If you don't know that much about threads and general Network IO, I would rather recommend liteNetLib (C#, Unity) or Mirror (Unity only).
Thanks a lot for your answer! Wish you happy everyday! Thanks again!