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.Connect locks up Netduino if no network


  • Please log in to reply
4 replies to this topic

#1 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 29 June 2012 - 06:58 PM

Hi,

I'm really having a big issue with the Socket.Connect() method locking up all the threads on the Netduino, when the server isn't available. I've read a few articles about this, but no matter how many threads I create the connection on, the Connect() line stops everything from happening.

I've created a thread that monitors the connection and creates a new one if it's not up. I use this to reconnect automatically if something goes wrong.

Has anyone experienced this and solved it? I'm running v4.1.2 firmware.

Connection thread:
 ThreadState state = ThreadState.Running;
                    Thread conThread = null;
                    while (state == ThreadState.Running)
                    {
                        Debug.Print("Attempting connection...");
                        if (conThread != null)
                            conThread.Abort();
                        conThread = new Thread(CreateConnection);
                        conThread.Start();
                        Thread.Sleep(500); // Wait 500ms for conThread to end, or continue looping until connected (hopefully?)
                        state = conThread.ThreadState;
                    }

The thread that creates the actual connection. It stops all threads from running once I start it (if no network cable is plugged in)
 public void CreateConnection()
        {
            try
            {
                Server.Connect(new IPEndPoint(IPAddress.Parse(Address), Port));
                //Thread.CurrentThread.Abort(); // A signal that we're connected (see for loop on owner thread)
            }
            catch (SocketException ex)
            {
                Debug.Print(ex.Message);
            }


#2 Teets

Teets

    Member

  • Members
  • PipPip
  • 16 posts

Posted 29 June 2012 - 08:41 PM

Server.Connect(new IPEndPoint(IPAddress.Parse(Address), Port));


Is Server a static variable declared in your main thread?

#3 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 29 June 2012 - 09:42 PM

Is Server a static variable declared in your main thread?

No, it's a public accessor of the class

#4 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 29 June 2012 - 11:52 PM


Has anyone experienced this and solved it? I'm running v4.1.2 firmware.


Yes, I have seen this in all the versions of N+ software and this issue continues in 4.2, at least so far. The only thing that worked reliably for me was to add an external hardware watchdog timer, as described in this thread:

Watchdog timer thread

---
Robert

#5 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 21 November 2012 - 09:27 AM

Hi there,

I'm having a similar problem where I try and access the wifi module to get the local IP (this just for testing and I actually want to create a socket and send an HTTP request) and it simply stops all threads from running.

Any ideas about why I can't access any network related stuff from within my interrupt event method?

Problem detailed here

Thanks,
Donovan




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.