/// <summary> /// Start listening to the UDP Connection. /// </summary> public void Listen() { try { byte[] bytesReceived = Listener.Receive(ref IPEndPoint); var bytesReceivedArgs = new UDPPacketReceivedEventArgs(bytesReceived); OnBytesReceived(bytesReceivedArgs); } catch (SocketException) { // The purpose of this catch is when Close or Dispose is called to stop listening. // Should be fine until a better solution is found on cancelling ongoing listen. } catch (ObjectDisposedException) { // The purpose of this catch is when Close or Dispose is called to stop listening. // Should be fine until a better solution is found on cancelling ongoing listen. } }
private void OnBytesReceived(UDPPacketReceivedEventArgs e) { BytesReceived?.Invoke(this, e); }