Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Socket Exception


  • Please log in to reply
8 replies to this topic

#1 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 06 June 2012 - 10:00 PM

Hi All,

I am trying to run a web service that I have built in connection with a project I am building. However I cannot for the life of me get my netduino to actually talk to my service.

Here is the code, does it look bad?
using (var request = (HttpWebRequest)WebRequest.Create(url))
            {
                request.Method = "GET";
                request.Accept = "application/json";
                request.UserAgent = "OomooTweetNetduino";
                try
                {
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            Debug.Print(response.StatusCode.ToString());

                            var textStream = response.GetResponseStream();

                            byte[] buffer = new byte[textStream.Length];

                            var count = textStream.Read(buffer, 0, int.Parse(textStream.Length.ToString()));

                            char[] chars = Encoding.UTF8.GetChars(buffer);

                            //var s = new string(chars).TrimEnd('

                            Debug.Print(new string(chars));
                        }

                    }

                    return true;

                }
                catch (Exception e)
                {
                    WriteAllErrors(e);
                    return false;
                }

            }


#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 June 2012 - 05:17 AM

Hello Adam. Not clear where is the problem, though. The above service is supposed to be hosted in a normal server (e.g. PC), while the client is the Netduino, right? If so, who is raising the exception? Again, could you check the TCP data flow with Wireshark or any similar tool? Cheers
Biggest fault of Netduino? It runs by electricity.

#3 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 07 June 2012 - 10:14 AM

Hi Mario,

The service is currently on the web, it is a simple REST service that returns JSON based on the requests.

My Netduino is trying to consume it.

the point at which I get the error is
using (var response = (HttpWebResponse)request.GetResponse())
it errors out and doesn't hit the next lines.

the inner exception is of type SocketExeption.

Adam

#4 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 07 June 2012 - 11:09 AM

Hi Adam

What is the URL you are using?

Excuse the bleeding obvious but...
If the url in your netduino code is localhost (which resolves to 127.0.0.1 aka local loopback address) then you are attempting to connect the netduino to itself, if thats the case try using the machine name or IP address of your computer running the REST service.

Another option is to use the lighter weight (in terms of RAM usage) http client in the netmf toolbox which i personally use to connect to various RESTful webservices as i have run into issues with ram utilisation and garbage collection using the standard netmf webrequest object.

Also what is the inner exception message?

Nak.

#5 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 07 June 2012 - 01:43 PM

Hi Nak, I have tried the http_Client and I got the same response, I cant remember the full request URL off of the top of my head as i am in work, but i will respond when I get home in a couple of hours. Adam

#6 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 07 June 2012 - 04:52 PM

Here is the url I am trying to get to
var url = "http://www.adam-clifford.co.uk/api/values/GetTweetHeaders/efc5adb9f17040e1bcbade6e210a467b";


#7 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 07 June 2012 - 07:52 PM

I assume the gateway and dns server settings are correct on your nd+?

#8 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 07 June 2012 - 07:58 PM

I forgot to add that i would do initial testing on your lan, by installing iis 7/iis express and running the service locally, that way you can control the environment better and if needs be wireshark the network to see what is going on. Also what if any are the inner exception(s) messages?

#9 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 08 June 2012 - 07:04 PM

these are the exceptions

-		e	{System.Net.WebException}	System.Exception {System.Net.WebException}
+		InnerException	{System.Net.Sockets.SocketException}	System.Exception {System.Net.Sockets.SocketException}
		m_HResult	4278190080	int {uint}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.