【发布时间】:2017-01-07 17:23:53
【问题描述】:
假设我有一个简单聊天室的客户端和服务器。
它们通过 JSON 字符串进行通信。
我了解以下示例不安全,但我只对这是一种有效的沟通方式感兴趣。
// The Client connects to the server.
// The Client sends a JSON string with the following variables to the server:
--> Intention: "Request"
--> Context: "Login"
--> Message: "username:admin|password:123"
// The Server receives the JSON string and the string goes through an if-statement:
--> if(Intention.Equals("Request")){...}else if(Intention.Equals("Response")){...}
// The Server now knows it's a Request and moves on to the next step.
--> if(Context.Equals("Login")){.<check if user exists in server database and if the login details match>.}
// If the login details are correct, The Server marks the connected Client as logged in and sends a JSON string back to The Client:
--> Intention: "Response"
--> Context: "Login"
--> Message: "OK"
// The Client receives the messages and sees it's OK, now the Client shows the user control panel and chatbox to the user which all send other Request JSON strings to The Server.
// Any other context than "Login" check if the Client actually is marked as logged in, if not, the server returns a response with "ERR_NOT_LOGGED_IN"
现在我有几个问题:
- 这是一种在客户端和服务器之间来回通信的有效/良好方式吗?
- 它有什么好处/坏处?
- 您对如何使沟通更好/更有效(内容方面)有什么建议吗?
- 如果这恰好是一家大公司的聊天服务器,并且密码不是以纯文本形式存储而是与私钥和公钥一起使用,那么还有什么大的安全漏洞?
我在问,因为我发现了很多关于客户端和服务器进行通信的 的好方法,而不是关于来回发送的实际 内容。 p>
提前谢谢你!
【问题讨论】:
标签: c# server client client-server communication