Sockets interaction (java)

三世轮回 提交于 2020-01-06 15:49:08

问题


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:

  1. authorization information like login, password;
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!