1
Vote

ReadResponse() Fails on High Latency Connections

description

It all comes down to this line in the ReadResponse() Method
// make sure any command sent has enough time to respond
Thread.Sleep(750);
Increasing the 750 to something like 5000 fixes the issue in our particular case but it's obviously not the right thing to do

What makes it worse is that nothing seems to happen.. You call BeginConnect and then you don't get any errors back.

comments

Alf99 wrote Mar 19, 2014 at 12:53 PM

I fixed it with a short Loop, so I didn't have to wait on fast awnsers
                Thread.Sleep(750);

                for (; m_cmdsocket.Available > 0; )
                {
                    bytesrecvd = m_cmdsocket.Receive(m_buffer, m_buffer.Length, 0);
                    responsetext += Encoding.ASCII.GetString(m_buffer, 0, bytesrecvd);
                }
                
                if (responsetext.Length == 0)
                {
                    Counter = 0;
                    //Do some Sleep until awnser
                    while (responsetext.Length == 0 && Counter < 4)
                    {
                       
                        Thread.Sleep(750);
                        bytesrecvd = 0;
                        for (; m_cmdsocket.Available > 0; )
                        {
                            bytesrecvd = m_cmdsocket.Receive(m_buffer, m_buffer.Length, 0);
                            responsetext += Encoding.ASCII.GetString(m_buffer, 0, bytesrecvd);
                        }
                        Counter++;
                    }
                    if (responsetext.Length == 0)
                    {
                        response.ID = 0;
                        response.Text = "";
                        return response;
                    }
                }