问题
I'm developing the real-time multiplayer game and I want to create fast and optimized interface between client and server sockets.
Client will send to server next information via socket:
- authorization information like login, password;
simple commands like:
- moveToPoint(coords)
- shootInDirection(coords)
- dropItem(item,coords) etc...
These commands(requests) have to be handled by server and transmitted to other clients;
The main question is: How to design the structure of commands which client will send with a high frequency? (json, string or numbers) I think, there are 2 factors that can affect speed and performance:
- command length (shorter -> faster)
complexity of parsing
In which way should I parse these commands? (one of the java libraries or simple split)?
How is it implemented in popular multiplayer games(Counter strike for e.g.)
Could you give me some advice or articles on this topic?
回答1:
As far as the client/server communicating, I would recommend taking a look at Netty, it seems to meet your requirements.
- It has complete SSL/TLS support
- Handles things like thread pools for you
- Low resource consumption
- ...And lots more
For starters, I would recommend checking out the examples to see how to do things such as sending strings, though in your case it might be a better idea to send POJOs, which as the article explains are Plain Old Java Objects, perhaps containing fields for location, etc.
来源:https://stackoverflow.com/questions/39500234/sockets-interaction-java