C# Webresponse没有';无法通过GSM连接工作
我正在尝试通过GSM VPN隧道发送http请求。下面是负责发送它的部分代码。我已经用“笨拙”测试过了,它可以在400-500毫秒内正常工作。但在将程序放入目标系统后,所有发送请求的尝试都以错误结束(“捕获”发生,设备中的输出不会改变其状态)。 GSM链路的位置很差(pings 80-400ms,偶然的数据包丢失等),但我希望多次尝试中至少有一次会成功。我的代码有什么问题 Webexception状态为:“超时” 完整的http链接如下所示: 192.168.1.100/outs.cgi?out0=0 答案是(设备中的输出状态为纯文本): 一万C# Webresponse没有';无法通过GSM连接工作,c#,gsm,httpwebresponse,C#,Gsm,Httpwebresponse,我正在尝试通过GSM VPN隧道发送http请求。下面是负责发送它的部分代码。我已经用“笨拙”测试过了,它可以在400-500毫秒内正常工作。但在将程序放入目标系统后,所有发送请求的尝试都以错误结束(“捕获”发生,设备中的输出不会改变其状态)。 GSM链路的位置很差(pings 80-400ms,偶然的数据包丢失等),但我希望多次尝试中至少有一次会成功。我的代码有什么问题 Webexception状态为:“超时” 完整的http链接如下所示: 192.168.1.100/outs.cgi?out
private int-switch\u-kontroler(字符串地址、int-outnr、int-state)
{
int i=0;
if(this.checkBox1.Checked==true)//我在表单中有checbox“启动GSM模式”
goto GSM;
其他的
后藤试验;
GSM:
如果(iOk,问题解决了。多亏了DavidG
看起来响应的时间要比ping长得多(纯文本中只有几个数字,所以我很惊讶)。我已经将超时时间提升到10秒,效果很好
广告:最后超时时间上升到了20秒,甚至15秒在大部分时间里都是一个问题(奇怪的是,如果有连接,我会在2-3秒内得到答案,但超时时间必须设置为10+)当捕获发生时,抛出的异常是什么?它以“timeout”结束状态。这有点奇怪,我已经开始了windows ping尝试,最长的响应时间是350ms(没有数据包丢失)350ms ping,通过GSM下载目标网页的时间还要多长?
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;
;
}