简体   繁体   English

客户端-服务器处理错误

[英]Client-Server handling errors

I want to build a Client-Server application using Socket from Java language. 我想使用Java语言中的Socket来构建Client-Server应用程序。 The Client communicates with the Server using different sequences of bytes. 客户端使用不同的字节序列与服务器通信。 My question is what's the best way to handling the correct format of the messages, to the Server side or both, Client and Server? 我的问题是,处理正确的消息格式(到服务器端还是从客户端到服务器)的最佳方法是什么? Thanks! 谢谢!

One initial thought: shared code! 最初的想法是:共享代码! If the code that is used to generate your byte sequences is the SAME on client and server (versus having two different implementations to do the same thing). 如果用于生成字节序列的代码是客户端和服务器上的SAME(相对于使用两种不同的实现来执行相同的操作)。

You will ALWAYS have to check the correctness and sanity of messages arriving at the server. 您将始终必须检查到达服务器的消息的正确性和完整性。 ALWAYS . 总是 Because people can ALWAYS reverse-engineer the protocol and develop their own clients. 因为人们总是可以对协议进行反向工程并开发自己的客户。 So whatever sanity checks you have in your client, they could be bypassed. 因此,无论您对客户进行的健全性检查如何,都可以绕开它们。

You might want to do the sanity checks in a library, as far as applicable, and use that library not only in the server but also in the client. 您可能想要在库中进行适用性检查,并不仅在服务器中而且在客户端中都使用该库。 Depending on your application, it might make sense to prevent insane messages from being generated in the client in the first place. 视您的应用程序而定,首先应该防止在客户端中生成疯狂的消息。 But as I said, that's no replacement for the server-side checks. 但是正如我所说,这不能替代服务器端检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM