protected void clientSocket_TCPDataArrival(ConferenceWebCommon.EntityCommon.PackageBase args) { try { if (Thread.CurrentThread.IsAlive) { if (this.clientSocket_TCPDataArrivalCallBack != null) { this.clientSocket_TCPDataArrivalCallBack(args); } } } catch (Exception ex) { //LogManage.WriteLog(this.GetType(), ex); } finally { } }
/// <summary> /// 接收从远程主机发送的数据(服务器端) /// </summary> private void GetRemoteData() { var dd = this._clientSocket.Available; try { while (this._clientSocket != null) { ConferenceWebCommon.EntityCommon.PackageBase code = null; List <byte> lists = new List <byte>(); callBack: byte[] buffer = new byte[BUFFER_SIZE]; int count = this._clientSocket.Receive(buffer);//挂起操作 if (this._clientSocket == null) { break; } if (count == 0) { //客户端与服务器端断开连接 break; } if (count == BUFFER_SIZE) { lists.AddRange(buffer); } else if (count < BUFFER_SIZE) { byte[] dataless = new byte[count]; Array.Copy(buffer, dataless, count); lists.AddRange(dataless); } if (this._clientSocket.Available != 0) { goto callBack; } byte[] data = lists.ToArray(); lists.Clear(); lists = null; MemoryStream stream = null; using (stream = new MemoryStream(data)) { stream.Position = 0; BinaryFormatter formatter = new BinaryFormatter(); code = formatter.Deserialize(stream) as ConferenceWebCommon.EntityCommon.PackageBase; } Array.Clear(data, 0, data.Length); data = null; //this._clientSocket.Close(); if (this.TCPDataArrivalCallBack != null) { this.TCPDataArrivalCallBack(code); } } } catch (Exception) { } }