public void BeginReceive(ISocketObject listener = null) { if (InternalSocket.Connected) { InternalSocket.BeginReceive(_ReceiveBuffer, 0, _ReceiveBuffer.Length, SocketFlags.None, ReceiveCallback, listener ?? this); } }
private void ReceiveCallback(IAsyncResult ar) { var owner = ar.AsyncState as SocketObject; var count = 0; try { count = InternalSocket.EndReceive(ar); } catch (Exception) { if (owner.SocketDisconnected != null) { owner.SocketDisconnected.Invoke(this); } Dispose(); return; } if (count == 0) { if (owner.SocketDisconnected != null) { owner.SocketDisconnected.Invoke(this); } Dispose(); return; } if (owner.ReceivedData != null) { owner.ReceivedData.Invoke(this, _ReceiveBuffer, 0, count); } if (InternalSocket.Connected) { InternalSocket.BeginReceive(_ReceiveBuffer, 0, _ReceiveBuffer.Length, SocketFlags.None, ReceiveCallback, ar.AsyncState); } }