private static void ReceiveCallback(IAsyncResult ar)//C> { try { UdpClient c = (UdpClient)((UdpState)(ar.AsyncState)).ut; IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e; Byte[] buffer = c.EndReceive(ar, ref e); if (buffer.Length > 0) { Issignal = true; int size = Marshal.SizeOf(Model.vSM); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(buffer, 0, ptr, size); Model.vSM = (Model.SM)Marshal.PtrToStructure(ptr, Model.vSM.GetType()); Model.vSM.depth = (float)((Model.vSM.depth) / 1.197);//конвертирование глубины из паскалей в сантиметры R = ""; for (int i = 0; i < buffer.Length; i++) { R += buffer[i] + " "; } if (R != "") { R = "ReceivedByteData: " + R; } else { R = "NO RECEIVED DATA"; } Marshal.FreeHGlobal(ptr); } UdpState s = new UdpState(); s.ut = c; s.e = e; c.BeginReceive(new AsyncCallback(ReceiveCallback), s); } catch (Exception ex) { Console.WriteLine("Возникло исключение: " + ex.ToString() + "\n " + ex.Message); Issignal = false; } }//C<
public void Receiver()//C> { // Создаем UdpClient для чтения входящих данных long time1, nowtime1; UdpState s = new UdpState(); s.e = m_RemoteIpEndPoint; s.ut = m_receivingUdpClient; try { long oldTime = DateTime.Now.Ticks; IAsyncResult res = m_receivingUdpClient.BeginReceive(new AsyncCallback(ReceiveCallback), s);// начинаем прием nowtime1 = DateTime.Now.Ticks; time1 = (nowtime1 - oldTime) / 1000; } catch (Exception ex) { Console.WriteLine("Возникло исключение: " + ex.ToString() + "\n " + ex.Message);//V } }