/// <summary> /// Starts listening for messages on the specified port /// </summary> public void Start(AsyncCallback callback) { if (_started) { return; } _started = true; IPAddress address = (this.localMessagesOnly ? IPAddress.Loopback : IPAddress.Any); IPEndPoint endpoint = new IPEndPoint(address, this.port); this.udp = new UdpClient(endpoint); this.port = ((IPEndPoint)udp.Client.LocalEndPoint).Port; // if 0 is passed, the system will assign a port. if (callback == null) { callback = new AsyncCallback(this.ProcessPacket); } UdpState state = new UdpState(); state.Udp = udp; state.Endpoint = endpoint; state.Callback = callback; udp.BeginReceive(callback, state); }