Java – Server Server / Server Server protocol. How do I submit orders?

I wrote a client-server pair for a 2D top down RPG game using sockets. However, I’m not clear on how exactly to transmit what the user wants to do.

Would I simply transmit a string like “Move north” and then use switch statements to decide what action to take or is there a more elegant solution?

If both client and server are java programs, then I would go with Command
pattern where each command class does a specific job (like “Move north” in your case) and the command objects are exchanged between the client and the server.

We used to use this approach in our enterprise application (though not a game), while implementing multi-master replication and it was quite extendible without any if/else chains or switch statements anywhere, just receive command and call command.execute() without worrying about what the command is.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Java – Server Server / Server Server protocol. How do I submit orders?

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录