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

Network Loss Problem


  • Please log in to reply
5 replies to this topic

#1 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 10 August 2012 - 08:53 PM

Hi all,

My program is able to connect to a remote server via a socket and it can send data across.
Upon disconnection (or if Ethernet cable is plugged in, after the device powering) I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

In this case, I frequently try to re-establish the connection by creating a new socket and reinitialising it, but the program is stopped in socket.connect(...) line after plugging in the Ethernet cable.

Would you please help me solve the problem?
Here is the code I wrote:
static Socket Connect(string host, int timeout, int port_num)
        {
            Socket connection;
            IPHostEntry hostEntry = Dns.GetHostEntry(host);                // Look up host’s domain name to find IP address(es)
            IPAddress hostAddress = hostEntry.AddressList[0];              // Extract a returned address
            IPEndPoint remoteEndPoint = new IPEndPoint(hostAddress, port_num);
            
            while (true)
            {
                try
                {
                    //Connect
                    connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    connection.Connect(remoteEndPoint);
                    connection.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
                    connection.SendTimeout = timeout;
                    Debug.Print("Connection stablished");

                    break;
                }
                catch (SocketException e)
                {
                    Debug.Print("Error Code: " + e.ErrorCode);
                    Debug.GC(true);
                }
            }
            Debug.GC(true);
            return connection;
        }


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 August 2012 - 09:38 AM

Hi mohammad, It appears that there is a bug in the current version of lwIP which does not like network cable disconnection/reconnection. .NET Micro Framework 4.3 upgrades to the newer lwIP release, and a bugfix for network connection issues is listed in its release notes. The 4.3 beta is scheduled for next month. I hate to push the issue off, but it looks like we need to update the IP stack to fix this particular glitch. Chris

#3 Victor M.

Victor M.

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationRio de Janeiro, Brazil

Posted 11 August 2012 - 01:55 PM

uau!!!!!!!!!!!!!!!!
Very good! I'm waiting months to this bug fix!


Hi mohammad,

It appears that there is a bug in the current version of lwIP which does not like network cable disconnection/reconnection.

.NET Micro Framework 4.3 upgrades to the newer lwIP release, and a bugfix for network connection issues is listed in its release notes. The 4.3 beta is scheduled for next month. I hate to push the issue off, but it looks like we need to update the IP stack to fix this particular glitch.

Chris



#4 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 05 September 2012 - 09:34 PM

Hi Chris and all,

No update yet? Would you please tell me how long I should wait for the fixing of the aforementioned bug?

Thank you so much,
Mohammad

Hi all,

My program is able to connect to a remote server via a socket and it can send data across.
Upon disconnection (or if Ethernet cable is plugged in, after the device powering) I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

In this case, I frequently try to re-establish the connection by creating a new socket and reinitialising it, but the program is stopped in socket.connect(...) line after plugging in the Ethernet cable.

Would you please help me solve the problem?
Here is the code I wrote:

static Socket Connect(string host, int timeout, int port_num)
        {
            Socket connection;
            IPHostEntry hostEntry = Dns.GetHostEntry(host);                // Look up host’s domain name to find IP address(es)
            IPAddress hostAddress = hostEntry.AddressList[0];              // Extract a returned address
            IPEndPoint remoteEndPoint = new IPEndPoint(hostAddress, port_num);
            
            while (true)
            {
                try
                {
                    //Connect
                    connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    connection.Connect(remoteEndPoint);
                    connection.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
                    connection.SendTimeout = timeout;
                    Debug.Print("Connection stablished");

                    break;
                }
                catch (SocketException e)
                {
                    Debug.Print("Error Code: " + e.ErrorCode);
                    Debug.GC(true);
                }
            }
            Debug.GC(true);
            return connection;
        }



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 September 2012 - 12:09 AM

Hi mohammad,

No update yet? Would you please tell me how long I should wait for the fixing of the aforementioned bug?

As I understand it, .NET MF 4.3 should be going into alpha/beta soon. They're finishing up a few things; we'll try to support it ASAP once it is posted.

Chris

#6 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 06 September 2012 - 11:46 PM

Hi Chris, Thanks for your update. So, I keep on waiting for this new firmware... Cheers, Mohammad




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.