Ejemplo n.º 1
0
        public IpPacket Send(IpPacket data, int time_out_mls, Socket s)
        {
            while (s.Available != 0)
            {
                s.Receive(TmpBuffer);
            }

            if (s.SendTo(data.Buffer, Destination) != data.Buffer.Length)
            {
                throw new Exception("Send data error...");
            }
            //--------------------------
            long tick_from = DateTime.Now.Ticks;

            //gui.MainForm.MForm.SetupTimeOut(time_out_mls / 1000F);
            while (s.Available == 0 &&
                   (DateTime.Now.Ticks - tick_from) / 10000 < time_out_mls)
            {
                Thread.Sleep(10);
            }
            //gui.MainForm.MForm.SetupTimeOut(0);
            if (s.Available == 0)
            {
                throw new Exception("No reply");
            }
            //--------------------------
            int      l = s.Receive(TmpBuffer);
            IpPacket p = new IpPacket(TmpBuffer, l);

            if (p.PacketSize + 8 != l)
            {
                throw new Exception("Wrong size of packet");
            }
            if (data.IsGoodReply(p) == false)
            {
                throw new Exception("Wrong reply: Command1=" + p.Command1 + " Command2=" + p.Command2);
            }
            return(p);
        }