简体   繁体   English

Web响应无法通过GSM连接工作

[英]Webresponse doesn't work through GSM connection

I'm trying to send http request through GSM VPN tunnel. 我正在尝试通过GSM VPN隧道发送http请求。 Below is part of code responsible for sending it. 以下是负责发送它的代码的一部分。 I've tested it using "clumsy", and it works fine up to 400-500ms. 我用“笨拙”测试了它,它可以工作到400-500毫秒。 But after getting program into target system, all tries to send request ends with error ("catch" occurs, out in device doesn't change its state). 但是在将程序引入目标系统之后,所有尝试发送请求都以错误结束(发生“捕获”,在设备中输出不会改变其状态)。 GSM link is at poor location (pings 80-400ms, incidental packet drops etc.), but i was expecting that at least one from many tries will end with success. GSM链路位置较差(ping 80-400ms,偶然丢包等),但我预计至少有一次尝试将以成功结束。 What is wrong in my code? 我的代码有什么问题?

Webexception status is: "Timeout" Webexception状态是:“超时”

Complete http link looks like: 完整的http链接如下:

192.168.1.100/outs.cgi?out0=0 192.168.1.100/outs.cgi?out0=0

Answer is (states of outs in device in plain text): 答案是(明文中的设备输出状态):

10000 10000

        private int switch_kontroler(string adress, int outnr, int state)
    {
        int i = 0;
        if (this.checkBox1.Checked == true) //I have checbox "start GSM mode" in Form
            goto GSM; 
        else
            goto Test;
   GSM:  
        if (i<3)
        {
            goto Test;
        }
        else
            goto Koniec;
   Test:
        try
            {
                i++;
                label3.Text = "Próba przełączenia: "+i;
                this.Refresh();
                WebRequest request = WebRequest.Create("http://" + adress + "/outs.cgi?out" + outnr + "=" + state);
                request.Method = "GET";
                request.Timeout = 1000; //BTW. Why program works up to 500ms if timeout is set at 1000?
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                string result = sr.ReadToEnd();
                label3.Text = result.ToString();
                if (result[outnr] - '0' == state)
                    if (result[outnr] == '1')
                    {
                        label3.Text = "Załączono kamerę";
                        return 1; //info to the rest of program about succes (or not) of this method
                    }
                    else
                    {
                        label3.Text = "Wyłączono kamerę";
                        return 0;
                    }
                this.Refresh();
                response.Close();
            }
            catch (WebException e)
            {
                label3.Text = "Przełączenie nieudane: " + e.Status;
                this.Refresh();
                if (this.checkBox1.Checked == true)
                    goto GSM;
                else
                    goto Koniec;
Koniec:
       return 2;
                ;
        }

Basically i'm on a "script kid" level in c# so if you can be that nice, provide maximally possible complete code, please ;-) 基本上我在c#中的“脚本小子”级别,所以如果你可以那么好,请提供最大可能的完整代码,请;-)

Ok, problem solved. 好的,问题解决了。 Thanks to DavidG 感谢DavidG

It looks that response travels much longer than ping (it's only few digits in plain text so i'm surprised). 它看起来响应比ping更长的时间(它只是纯文本中的几个数字所以我很惊讶)。 I've rised timeout to 10 seconds and it works fine. 我已经超时到10秒,它运行正常。

Ad.: Finally timeout rised to 20 seconds, even 15 was creating a problem for much part of time (Oddly, if there is connection, I get answer in 2-3 seconds, but timeout must be set to value 10+) 广告:最后超时上升到20秒,甚至15在很长一段时间内都会产生问题(奇怪的是,如果有连接,我会在2-3秒内得到答案,但超时必须设置为10+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM