简体   繁体   中英

Client-Server handling errors

I want to build a Client-Server application using Socket from Java language. 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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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