After I connect to PPP I send data via HTTP to a server. I make 2 HTTP requests and they both go through until the second one then shows the following exception. After this nothing will be sent to the server until I restart the system.
I need to be able to recover from any errors.
The thread '<No Name>' (0xc) has exited with code 0 (0x0).
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (8) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::recv [IP: 0000] ####
#### System.Net.Sockets.Socket::Receive [IP: 0018] ####
#### System.Net.Sockets.NetworkStream::Read [IP: 0062] ####
#### System.Net.InputNetworkStreamWrapper::RefillInternalBuffer [IP: 0038] ####
#### System.Net.InputNetworkStreamWrapper::Read_HTTP_Line [IP: 004b] ####
#### System.Net.HttpWebRequest::ParseHTTPResponse [IP: 002e] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 0035] ####
#### MNTEnergy7.GSMmodemClass::SendSCADA [IP: 02c7] ####
#### MNTEnergy7.GSMmodemClass::gsmHandler [IP: 02d0] ####
#### SocketException ErrorCode = -1728053248
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = -1728053248
#### SocketException ErrorCode = -1728053248
#### SocketException ErrorCode = -1728053248
#### Exception System.Net.WebException - 0x00000000 (8) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### MNTEnergy7.GSMmodemClass::SendSCADA [IP: 02c7] ####
#### MNTEnergy7.GSMmodemClass::gsmHandler [IP: 02d0] ####
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
I am using the following code to make the connection. sensorData contains the URL for the request. It works for the first 2 calls to the function.
using (var req = HttpWebRequest.Create(sensorData) as HttpWebRequest)
{
try
{
req.Timeout = 10000; // 10 seconds timeout
using (var res = req.GetResponse() as HttpWebResponse)
{
using (var stream = res.GetResponseStream())
{
int offset = 0;
do
{
read = stream.Read(result, offset, result.Length - offset);
offset += read;
Thread.Sleep(20);
}
while (read != 0);
reply = new String(System.Text.Encoding.UTF8.GetChars(result));
}
}
}
catch (Exception)
{
return false;
}
}