public void CloseNet() { if (clienSocket != null) { try { clienSocket.Close(); clienSocket = null; } catch { } } }
void LoadNet() { try { #region remoting 断线重连 try { if (IsRmCon == false) { remoteobj = (IDBMethod)Activator.GetObject(typeof(IDBMethod), "tcp://" + pidServer_Ip + ":" + pidServer_RMPort + "/RemoteService"); IsRmCon = true; } } catch (Exception ex) { if (ex.Message.IndexOf("积极拒绝") != -1) { IsRmCon = false; } } #endregion //Kevin 2012-07-24 屏蔽 #region socket 断线自动重连 if (clienSocket != null) { if (clienSocket.Connected == false) //断线重连 { clienSocket.Close(); clienSocket = null; Thread.Sleep(1000); clienSocket = new ClientSocketSync(pidServer_Ip, pidServer_SKPort); clienSocket.OnConnection += new ClientSocketSync.Connection(clienSocket_OnConnection); clienSocket.OnCloseConnection += new ClientSocketSync.CloseConnection(clienSocket_OnCloseConnection); clienSocket.OnError += new ClientSocketSync.Error(clienSocket_OnError); clienSocket.OnReceivedBigData += new ClientSocketSync.ReceivedBigData(clienSocket_OnReceivedBigData); clienSocket.OnSendData += new ClientSocketSync.SendData(clienSocket_OnSendData); clienSocket.ConnectionServer(); if (clienSocket.IsBound) { IsSkCon = true; } } } else { clienSocket = new ClientSocketSync(pidServer_Ip, pidServer_SKPort); clienSocket.OnConnection += new ClientSocketSync.Connection(clienSocket_OnConnection); clienSocket.OnCloseConnection += new ClientSocketSync.CloseConnection(clienSocket_OnCloseConnection); clienSocket.OnError += new ClientSocketSync.Error(clienSocket_OnError); clienSocket.OnReceivedBigData += new ClientSocketSync.ReceivedBigData(clienSocket_OnReceivedBigData); clienSocket.OnSendData += new ClientSocketSync.SendData(clienSocket_OnSendData); clienSocket.ConnectionServer(); if (clienSocket.IsBound) { IsSkCon = true; } } #endregion Thread.Sleep(1000); } catch { IsSkCon = false; Thread.Sleep(1000); } }