private void InitializeOperation() { try { IsActive = true; IsAuthenticated = false; EndPoint = (IPEndPoint)AcceptedClient.RemoteEndPoint; LastReceive = DateTime.Now; LastSent = DateTime.Now; TotalBytesReceived = 0; TotalBytesSent = 0; HeaderStore = new byte[Config.GetHeaderSize()]; BufferQueue = new Queue <byte[]>(); BufferQueueLock = new object(); IsBuffering = false; IsBufferingLock = new object(); ReadOffset = 0; WriteOffset = 0; MessageSize = 0; State = BufferState.HEADER; Value = null; } catch (Exception ex) { OnClientException?.Invoke(this, ex); } }
private void StartReceive(SocketAsyncEventArgs ReceiveEventArgs) { try { if (IsActive) { if (ReceiveEventArgs == null) { ReceiveEventArgs = new SocketAsyncEventArgs(); ReceiveEventArgs.SetBuffer(new byte[Config.GetBufferSize()], 0, Config.GetBufferSize()); ReceiveEventArgs.Completed += IO_Completed; } if (!AcceptedClient.ReceiveAsync(ReceiveEventArgs)) { ProcessReceive(ReceiveEventArgs); } } } catch { OnClientException?.Invoke(this, new Exception("Cannot access a disposed object: Socket")); } }
private void SetOnClientException(Operation Client, Exception Ex) { OnClientException?.Invoke(Client, Ex); }