I have been bothering with this same issue for couple of hours with no result. I want to log to my local PHP webservice (which is deliberately offline for testing purposes) unfortunately Netduino does not throw timeout exception, but it hangs on this line even though timeout is set to 5000 ms.
HttpWebResponse response = (HttpWebResponse) webrequest.GetResponse();
I include my piece of code:
try
{
if (_isNetworkAvailable)
{
HttpWebRequest webrequest = (HttpWebRequest) HttpWebRequest.Create("http://" + server + url);
webrequest.Method = "GET";
webrequest.Timeout = 5000;
webrequest.KeepAlive = false;
HttpWebResponse response = (HttpWebResponse) webrequest.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var buffer = new char[5];
var builder = new StringBuilder();
while (reader.Read(buffer, 0, 5) > 0)
builder.Append(buffer);
reader.Close();
reader.Dispose();
response.Close();
response.Dispose();
return builder.ToString();
}
}
else { return null; }
}
else {
throw new Exception("Network cable unavailable");
}
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
}
return null;
}
catch(Exception ex) {
Debug.Print(ex.Message);
return null;
}