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.

Vincent Guillemette

Member Since 15 Jun 2011
Offline Last Active Aug 12 2011 01:48 PM
-----

Posts I've Made

In Topic: Socket.Connect blocks all threads?

13 July 2011 - 07:31 PM

I’m also having problems using sockets on Netduino Plus.

I tried with 4.1.x and 4.2 b1, and it's still freezing the Netduino Plus:

I discovered that the freeze occurs sometime during the socket instantiation. I assumed that the socket has to be disposed in order to clear the IP stack or something like it, so i tried to use the using() statement:

using (Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) trick.

Unfortunately it did not work. When it succesfully instanciated the socket, the connect statement does throw an exception only if my Ethernet cables is pluged. This is hard to test so I'm not sure.

I need this feature in my application, so thanks for the post to correct these problems.

The flashing led, is used to verify that the debugger is not involved in the forementioned problem.
Here my test code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace SocketFreeze
{
    public class Program
    {
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            IPAddress address = IPAddress.Parse("192.168.1.142");
            IPEndPoint endPoint = new IPEndPoint(address, 80);
            using (Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                try
                {
                    mySocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
                    mySocket.Connect(endPoint);
                }
                catch (SocketException e)
                {
                    Debug.Print("Socket Exception" + e.ToString());
                }
                mySocket.Close();
            }

            while (true)
            {
                Thread.Sleep(500);
                led.Write(true);
                Thread.Sleep(500);
                led.Write(false);
            }
        }

    }
}

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.