private void ReceiveData(IAsyncResult asyncResult) { try { // Initialise the IPEndPoint for the client EndPoint epSender = new IPEndPoint(IPAddress.Any, 0); // Receive all data int msgLen = recvSocket.EndReceiveFrom(asyncResult, ref epSender); byte[] localMsg = new byte[msgLen]; Array.Copy(buffer, localMsg, msgLen); // Listen for more connections again... recvSocket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveData), epSender); int port = ((IPEndPoint)epSender).Port; // Update status through a delegate mf.Invoke(HandleDataDelegate, new object[] { port, localMsg }); } catch (Exception e) { mf.Tls.WriteErrorLog("UDP Recv data " + e.ToString()); mf.Tls.TimedMessageBox("ReceiveData Error", e.Message); } }
private void ReceiveData(IAsyncResult asyncResult) { try { // Initialise the IPEndPoint for the client EndPoint epSender = new IPEndPoint(IPAddress.Any, 0); // Receive all data int msgLen = recvSocket.EndReceiveFrom(asyncResult, ref epSender); byte[] localMsg = new byte[msgLen]; Array.Copy(buffer, localMsg, msgLen); // Listen for more connections again... recvSocket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveData), epSender); int port = ((IPEndPoint)epSender).Port; // Update status through a delegate mf.Invoke(HandleDataDelegate, new object[] { port, localMsg }); } catch (System.ObjectDisposedException) { // do nothing } catch (Exception e) { mf.Tls.ShowHelp("ReceiveData Error \n" + e.Message, "Comm", 3000, true); } }