public UdpCom(IPAddress address, int port) { uEndpoint = new IPEndPoint(address, port); // uClient = new UdpClient (uEndpoint); uState = new UdpState(new UdpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port)), uEndpoint); receiveFlag = false; uState.client.BeginReceive(new AsyncCallback(RxCallback), uState); rxBytesBuffer = new List <byte[]> (); }
public void RxCallback(IAsyncResult result) { UdpState rState = (UdpState)result.AsyncState; UdpClient rClient = ((UdpState)result.AsyncState).client; IPEndPoint rEndPoint = ((UdpState)result.AsyncState).endpoint; byte[] rxBytes = rClient.EndReceive(result, ref rEndPoint); rxBytesBuffer.Add(rxBytes); Console.WriteLine("Received Bytes ___________________________"); Console.WriteLine(rxBytes.ToString()); receiveFlag = true; rClient.BeginReceive(new AsyncCallback(RxCallback), result.AsyncState); }