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 Problem Again?


  • Please log in to reply
6 replies to this topic

#1 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 01 September 2012 - 11:43 AM

Hello ,
I wish someone could help , i dont know if its a bug ....
here is a code that worked on two pcs without any problem ..
i am trying the same on the netduino plus

Netduino plus code
LedPin = new OutputPort(Pins.ONBOARD_LED, false);
            Interface = NetworkInterface.GetAllNetworkInterfaces()[0];
            Interface.EnableStaticIP("192.168.15.4", "255.255.255.0", "192.168.15.1");
            Thread.Sleep(5000);
            Debug.Print("ip: " + Interface.IPAddress);
            LedPin.Write(true);
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 90);
            sock.Bind(ip);
            sock.Listen(1);
            Socket _sock;
            NetworkStream _NetStream;
            while (true)
            {
                _sock = sock.Accept();
                _NetStream = new NetworkStream(_sock);
                for (int i = 0; i < 10; i++)
                    _NetStream.WriteByte(48);
                _NetStream.Close();
                _sock.Close();
            }

Here Is The Pc Code:

private void button1_Click(object sender, EventArgs e)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect(IPAddress.Parse("192.168.15.4"), 90);
            NetworkStream ns = new NetworkStream(sock);
            char x;
            for (int i = 0; i < 10; i++)
                x = (char)ns.ReadByte();
            ns.Close();
            sock.Close();
        }

it gets an exception microsoft.spot.io , still dont know why , i would like some help

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 September 2012 - 03:18 PM

Hi Nart, What line of code is throwing the exception? What specific exception is it throwing? Chris

#3 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 01 September 2012 - 07:06 PM

Hi Nart,

What line of code is throwing the exception?

What specific exception is it throwing?

Chris


Hey Chris,
Here Is A Snap Shot On The Netduino Side

Attached Files



#4 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 01 September 2012 - 11:55 PM

Hi Nart,

What line of code is throwing the exception?

What specific exception is it throwing?

Chris


Hey Chris,
I found a solution by trying the following , it was the only solution maybe this will help you more...
i changed the netduino code to the following:

LedPin = new OutputPort(Pins.ONBOARD_LED, false);
            Interface = NetworkInterface.GetAllNetworkInterfaces()[0];
            Interface.EnableStaticIP("192.168.15.4", "255.255.255.0", "192.168.15.1");
            Thread.Sleep(5000);
            Debug.Print("ip: " + Interface.IPAddress);
            LedPin.Write(true);
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 90);
            sock.Bind(ip);
            sock.Listen(1);
            Socket _sock;
            NetworkStream _NetStream;
            StreamReader Reader;// added a reader
            while (true)
            {
                _sock = sock.Accept();
                _NetStream = new NetworkStream(_sock);
                Reader=new StreamReader(_NetStream);//<--
                for (int i = 0; i < 10; i++)
                    debug.print(Reader.ReadLine());
                Reader.Close();
                _NetStream.Close();
                _sock.Close();
            }

As For The Pc Code I Changed To The Following:
private void button1_Click(object sender, EventArgs e)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect(IPAddress.Parse("192.168.15.4"), 90);
            NetworkStream ns = new NetworkStream(sock);
            StreamWriter Writer=new StreamWriter(ns);
            char x;
            for (int i = 0; i < 10; i++)
                Writer.WriteLine("Hello");
            Writer.Close();
            ns.Close();
            sock.Close();
        }

This Code Worked Perfectly , but the strange thing it didnt work with network stream only .....

#5 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 20 October 2012 - 10:55 AM

Am Still Gettings Exceptions i think it is related to internal problem call, i tried polling read and write and still gives me exception any solutions to the problem?

#6 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 20 October 2012 - 11:45 AM

Am Still Gettings Exceptions i think it is related to internal problem call, i tried polling read and write and still gives me exception any solutions to the problem?

huummm. It sounds like a wrong config.
What is the reason for port 90. tried another port with forwarding?
Deploy a static IP to your netduino and quote ' Interface.EnableStaticIP
Look at your router, ? port forwarding, mac address, DHCP (maybe DHCP reservation on the mac address)?

#7 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 24 October 2012 - 05:17 PM

huummm. It sounds like a wrong config.
What is the reason for port 90. tried another port with forwarding?
Deploy a static IP to your netduino and quote ' Interface.EnableStaticIP
Look at your router, ? port forwarding, mac address, DHCP (maybe DHCP reservation on the mac address)?


Hello Thanks For The Reply :),
actually am using static ip address , in networking theirs no problem for that port since it works between 2 pcs with ease so i guess if someone has tried that thing ? and got the same error, i think theirs somthing wrong in the lwip stack .. dunno !




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.