谷歌我的问题有点棘手,因为它更多的是关于过程的问题,而不是严格的技术问题。通过TCP处理客户端/服务器通信 - 一般问题
我正在建立一个基本的TCP客户机/服务器系统,我想知道来回通信应如何理想地工作。在我的具体情况下,客户端必须提交登录凭证,并从服务器发出特定请求(服务器与远程数据库交互)。
下面是我想做的事..我只是从其他开发者的输入来看。
SERVER: Wait for new connections
CLIENT: Connects to server
CLIENT: Once connected, send login credentials with an instruction code.
i.e. $LOGIN$,username,password
SERVER: Check instruction code, if code = $LOGIN$, try to authenticate
SERVER: If authentication fails, send user message saying login failed
i.e. $MSG$,101,Login Failed
CLIENT: If instruction code = $MSG$ and if message id = 101, display message and disconnect.
而另一种情况..让我们说客户想请求日志发生了什么事在服务器上最近(控制台应用程序窗口的文本)。被请求
CLIENT: Send request message to server for recent log
i.e. $REQ$,105
SERVER: If instruction = $REQ$ and request id = 105, get window text and send to client
i.e. $DATA$,105,<data here>
CLIENT: If instruction = $DATA$ and data id = 105, parse data and display to user
的数据可能是纯文本,或者.NET数据表转换成XML等,这可能是很多方面的事情。
思考呢?提示?
谢谢!
也许这个问题可能会被重写为更加“规范”的形式:“如何在.NET中使用TCP实现双向通信?” – hemp 2011-05-25 17:27:41