谷歌我的問題有點棘手,因爲它更多的是關於過程的問題,而不是嚴格的技術問題。通過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