Main Site Documentation

Cerbuino hangs with httpwebrequest


#1

Hi,

I have a function that sends some data to a webserver.

The function works well when the server is online. But when the server is offline for some reason the controller hangs.
I hade the same problem with the panda II
Using .net 4.2

try catch doesn’t work.

the problem starts in line
Stream dataStream = request.GetRequestStream();

After a while I get an out of memory.Failed allocation for 514 blocks, 6168 bytes

request.timeout = x; doesn’t help
request.readwrite = x; doesn’t help

I used also some examples from codeshare but they have all the same result.


                // Create a request using a URL that can receive a post. 
                WebRequest request = WebRequest.Create(_ClubInterfacePath);
                // Set the Method property of the request to POST.
                request.Method = "POST";
                // Create POST data and convert it to a byte array.
                string postData = "<clubrequest token=\"" + _Token + "\" " + Xml + " />"; ;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                Debug.Print(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
                // Display the content.


                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();

                return responseFromServer;

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Hardware (4.2.0.0)
Assembly: Microsoft.SPOT.Graphics (4.2.0.0) Assembly: Microsoft.SPOT.TinyCore (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0) Assembly: Microsoft.SPOT.IO (4.2.0.0)
Assembly: System.IO (4.2.0.0) Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0) Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)
Assembly: Microsoft.SPOT.Net (4.2.0.0) Assembly: System (4.2.0.0) Loading Deployment Assemblies.

Assembly: GHIElectronics.Gadgeteer.FEZCerbuinoBee (1.1.1.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: Gadgeteer.WebClient (2.42.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net.Security (4.2.0.0) Attaching deployed file.

Assembly: GHI.OSHW.Hardware (4.2.3.1) Attaching deployed file.

Assembly: System.Http (4.2.0.0) Attaching deployed file.

Assembly: GadgeteerApp1 (1.0.0.0) Attaching deployed file.

Assembly: System.Net.Security (4.2.0.0) Resolving.

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.OneWire.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI OSHW NETMF v4.2 SDK\Assemblies\le\GHI.OSHW.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Mainboards\FEZCerbuinoBee\NETMF 4.2\le\GHIElectronics.Gadgeteer.FEZCerbuinoBee.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Http.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.WebClient.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘O:\FEZ\Cerberus Cerbuino Bee\MyFirstApp\GadgeteerApp1\bin\Debug\le\GadgeteerApp1.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZCerbuinoBee version 1.2
Program Started
Initializing network…
Waiting for an IP Address…
IP Address: xxxxxxxxxx
The thread ‘’ (0x3) has exited with code 0 (0x0).
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.GetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.TransferEncoding.get’
Step into: Stepping over non-user code 'System.Net.WebHeaderCollection.this[string].get’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Collections.ArrayList.Count.get’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Collections.ArrayList.Count.get’
Step into: Stepping over non-user code 'System.Net.HeaderValueCollection.GetValuePair’
Step into: Stepping over non-user code 'System.Net.WebHeaderCollection.this[string].get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.TransferEncoding.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ContentLength.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.ValidateGetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.GetRequestStream’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.SubmitRequest’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Uri.Host.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Uri.Port.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'string.Concat’
Step into: Stepping over non-user code 'string.ToString’
Step into: Stepping over non-user code 'string.Concat’
Step into: Stepping over non-user code 'string.ToString’
Step into: Stepping over non-user code 'string.Concat’
Step into: Stepping over non-user code 'int.ToString’
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.CurrentInfo.get’
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get’
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get’
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.CurrentInfo.get’
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.NumberFormat.get’
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.CurrentInfo.get’
Step into: Stepping over non-user code 'int.ToString’
Step into: Stepping over non-user code 'System.Number.Format’
Step into: Stepping over non-user code 'System.Number.ValidateFormat’
Step into: Stepping over non-user code 'System.Number.ValidateFormat’
Step into: Stepping over non-user code 'System.Number.ValidateFormat’
Step into: Stepping over non-user code 'System.Number.ValidateFormat’
Step into: Stepping over non-user code 'System.Number.Format’
Step into: Stepping over non-user code 'System.Number.Format’
Step into: Stepping over non-user code 'System.Number.PostProcessInteger’
Step into: Stepping over non-user code 'System.Number.ReplaceNegativeSign’
Step into: Stepping over non-user code 'System.Number.ReplaceNegativeSign’
Step into: Stepping over non-user code 'System.Number.PostProcessInteger’
Step into: Stepping over non-user code 'System.Number.Format’
Step into: Stepping over non-user code 'int.ToString’
Step into: Stepping over non-user code 'string.Concat’
Step into: Stepping over non-user code 'string.Concat’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Collections.ArrayList.ArrayList’
Step into: Stepping over non-user code 'System.Collections.ArrayList.ArrayList’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Collections.ArrayList.Count.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Collections.ArrayList.Count.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Uri.HostNameType.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Uri.Host.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.ConvertStringToInt32’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.IPAddress.IPAddress’
Step into: Stepping over non-user code 'System.Net.IPAddress.IPAddress’
Step into: Stepping over non-user code 'System.Net.IPAddress.Parse’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Socket’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Socket’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Socket’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.SetSocketOption’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Uri.Port.get’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.IPEndPoint.IPEndPoint’
Step into: Stepping over non-user code 'System.Net.EndPoint.EndPoint’
Step into: Stepping over non-user code 'System.Net.EndPoint.EndPoint’
Step into: Stepping over non-user code 'System.Net.IPEndPoint.IPEndPoint’
Step into: Stepping over non-user code 'System.Net.HttpWebRequest.EstablishConnection’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Connect’
Step into: Stepping over non-user code 'System.Net.IPEndPoint.Serialize’
Step into: Stepping over non-user code 'System.Net.SocketAddress.SocketAddress’
Step into: Stepping over non-user code 'System.Net.SocketAddress.SocketAddress’
Step into: Stepping over non-user code 'Microsoft.SPOT.Debug.Assert’
Step into: Stepping over non-user code 'System.Net.SocketAddress.SocketAddress’
Step into: Stepping over non-user code 'System.Net.IPEndPoint.Serialize’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Connect’
Step into: Stepping over non-user code 'System.Net.Sockets.Socket.Connect’
Step into: Stepping over non-user code ‘System.Net.Sockets.Socket.Poll’


#2

@ d-ray -

Maybe the size of the stream exceed your memory available at the same moment. What does the request file contains ?


#3

@ andre.m - ReadWriteTimeout exists in 4.1 not in 4.2


#4

@ LouisCpro -
Hi thanks for the repy.

It is Ok when the webserver is online.
the request is only a string from ±50 char


#5

which socket do you have your ENC28 connected to, if its 5, try moving it to 6 if you can and give it a go and see if that makes a difference.


#6

Hi,
I tested with the cerb40 (socket 6 connections) and have the same problem.

@ andre.m where can i create a ticket @ netmf?