示例#1
0
文件: MCA.cs 项目: hnordquist/INCC6
        public MCAResponse[] SendBroadcast(MCACommand command, TimeSpan timeout)
        {
            Udp.Client.SendTimeout = (int)Math.Round(timeout.TotalMilliseconds);

            foreach (IPEndPoint sendIP in GetBroadcastSendIPs())
            {
                Udp.Send(command.Bytes, command.Bytes.Length, sendIP);
            }

            List<MCAResponse> responseList = new List<MCAResponse>();
            IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);
            DateTime endTime = DateTime.UtcNow + timeout;
            while (timeout > TimeSpan.Zero)
            {
                Udp.Client.ReceiveTimeout = (int)Math.Round(timeout.TotalMilliseconds);
                byte[] receivedBytes = null;
                try
                {
                    receivedBytes = Udp.Receive(ref from);
                }
                catch { } // SocketException for example upon a timeout
                if (receivedBytes != null)
                {
                    MCAResponse response = MCAResponse.ParseResponse(receivedBytes);
                    if (response != null && response.CommandName == command.CommandName)
                    {
                        response.RemoteAddress = from.Address;
                        responseList.Add(response);
                    }
                }
                timeout = endTime - DateTime.UtcNow;
            }

            MCAResponse[] responses = new MCAResponse[responseList.Count];
            responseList.CopyTo(responses);
            return responses;
        }
示例#2
0
文件: MCA.cs 项目: hnordquist/INCC6
 public MCAResponse[] SendBroadcast(MCACommand command)
 {
     return SendBroadcast(command, new TimeSpan(0, 0, 1));
 }
示例#3
0
文件: MCA.cs 项目: hnordquist/INCC6
 public MCAResponse Send(MCACommand command, TimeSpan timeout)
 {
     return Send(command, timeout, DefaultRetryCount);
 }
示例#4
0
文件: MCA.cs 项目: hnordquist/INCC6
        public MCAResponse Send(MCACommand command, TimeSpan timeout, uint retryCount)
        {
            Udp.Client.SendTimeout = (int)Math.Round(timeout.TotalMilliseconds);
            Udp.Client.ReceiveTimeout = (int)Math.Round(timeout.TotalMilliseconds);

            IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);
            MCAResponse response = null;
            for (int i = 0; i < retryCount; i += 1)
            {
                Udp.Send(command.Bytes, command.Bytes.Length, SendIP);
                byte[] receivedBytes = null;
                try
                {
                    receivedBytes = Udp.Receive(ref from);
                }
                catch { }
                if (receivedBytes != null)
                {
                    response = MCAResponse.ParseResponse(receivedBytes);
                    if (response != null && response.CommandName == command.CommandName)
                    {
                        response.RemoteAddress = from.Address;
                        break;
                    }
                }
            }
            return response;
        }
示例#5
0
文件: MCA.cs 项目: hnordquist/INCC6
 public MCAResponse Send(MCACommand command)
 {
     return Send(command, DefaultTimeout);
 }