1. 程式人生 > >遠程協助開發總結(二)

遠程協助開發總結(二)

控制 amp 為什麽不能 username 開發 col dsc exce nec

遠程協助開發的過程中繼續總結

針對開發總結一的問題,改正了一些地方

1.圖像和命令采用兩個套接字,為什麽不能采用一個套接字?遠程協助是快頻的通信,圖像需要不間斷的從受控端發送到控制端,發送接收壓力都很大,另外控制端還要發送鼠標和鍵盤命令到受控段,這個發送頻率在操作的時候也很大。所以使用一個套接字壓力太大。

2.圖像的傳輸,圖像比較大一般100-300K,所以需要多次分發,為了保證分發的安全性,先發送文件大小,再發送文件內容

3.命令的傳輸,不適合像文件那樣的精確發送,可以設置一個緩沖,一般幾百k的大小,受控段做好粘包的處理

4.不能只考慮Socket的關閉,socket所在的通信線程也要及時終止

安全的方式是這樣寫

 catch (SocketException ex)
                {
                    CommandLog.WriteClientLog("Receive Command SocketException", ex.Message);

                    break;
                }
                catch (ThreadAbortException ex)
                {
                    CommandLog.WriteClientLog(
"Receive Command ThreadAbortException", ex.Message); break; } catch (Exception ex) { CommandLog.WriteClientLog("Receive Command Exception", ex.Message); }

關閉socket

 public void CloseConnect()
        {
            
if (ImageSocket != null && ImageSocket.Connected) { try { ImageSocket.Shutdown(SocketShutdown.Both); } finally { ImageSocket.Close(); } } if (CommandSocket != null && CommandSocket.Connected) { try { CommandSocket.Shutdown(SocketShutdown.Both); } finally { CommandSocket.Close(); } } ImageSocket = null; CommandSocket = null; IsControled = false; IsControler = false; if (CommandThread != null) { CommandThread.Abort(); } if (SendScreenThread != null) { SendScreenThread.Abort(); } if (ImageThread != null) { ImageThread.Abort(); } if (ClientUser != null) { lock (_lock) { if (ClientUser != null) { string userName = ClientUser.UserName; ClientUser = null; if (UserLogout != null) { this.Form.Invoke(UserLogout, this, new LoginEventArgs(new LoginResultCommand { UserName = userName })); } } } } }

遠程協助開發總結(二)