Exemplo n.º 1
0
        public string SendRead(string lin)
        {
            string lout;

            if (_ClientOpen)
            {
                SW.WriteLine(lin);
                System.Threading.Thread.Sleep(50);
                if (TNETSocket.Available > 0)
                {
                    byte[] rec_buf = new byte[TNETSocket.Available];
                    Thread.Sleep(10);
                    int ret_len = TNETSocket.Receive(rec_buf);
                    lout = PP.GetString(rec_buf, ret_len);
                    return(lout);
                }
                else
                {
                    return("!error! timeout");
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public void ReadStr(out string t, out int ret_time, int tmo = 100)
        {
            t = "";
            bool tmo_reached = false;
            int  this_t      = 0;

            if (_ClientOpen)
            {
                DateTime s = DateTime.Now;
                while (TNETSocket.Available == 0 && !tmo_reached)
                {
                    Thread.Sleep(5);
                    this_t += 5;
                    if (this_t > tmo)
                    {
                        tmo_reached = true;
                    }
                }
                if (!tmo_reached)
                {
                    byte[] rec_buf = new byte[TNETSocket.Available];
                    Thread.Sleep(10);
                    int ret_len = TNETSocket.Receive(rec_buf);
                    t = PP.GetString(rec_buf, ret_len);
                }
            }
            ret_time = this_t;
        }
Exemplo n.º 3
0
        public bool ReadStr(out string t, out int ret_time, int tmo = 250)
        {
            t = "";
            bool tmo_reached = false;
            int  this_t      = 0;

            if (_ClientOpen)
            {
                DateTime timeLimit = DateTime.Now.AddMilliseconds(tmo);
                while (TNETSocket.Available == 0 && !tmo_reached)
                {
                    Thread.Sleep(5);
                    this_t += 5;
                    if (DateTime.Now > timeLimit)
                    {
                        tmo_reached = true;
                    }
                }
                if (!tmo_reached)
                {
                    while (TNETSocket.Available > 0)
                    {
                        byte[] rec_buf = new byte[TNETSocket.Available];
                        int    ret_len = TNETSocket.Receive(rec_buf);
                        t += PP.GetString(rec_buf, ret_len);
                        Thread.Sleep(100);          //Wait a little before it checks the socket again
                    }
                    t = t.Trim(new char[] { '>' }); //remove >
                    t = t.Trim(Environment.NewLine.ToCharArray());
                }
            }
            ret_time = this_t;
            return(tmo_reached);
        }