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

Cannot connect to Netduino Plus 2 socket without debugging


  • Please log in to reply
3 replies to this topic

#1 rchelicopter

rchelicopter

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Diego, Ca

Posted 29 December 2012 - 02:53 AM

Hello, I have been playing around with the Plus 2 and 4.2.1.2 and I just noticed that i can't connect to the socket if the usb "and" debugger are not running.  It works fine otherwise.   Can someone please have a look at this and see if I'm just doing something wrong.
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.Netduino;using System.Text; namespace Socket_Server{    public class Program    {        public static void Main()        {            using (System.Net.Sockets.Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))            {                socket.Bind(new IPEndPoint(IPAddress.Any, 10100));                socket.Listen(1);                {                     while (true)                    using (Socket NetduinoSocket = socket.Accept())                    {                        byte[] buffer = Encoding.UTF8.GetBytes("You Are Now Connected.....");                        NetduinoSocket.Send(buffer, 0, buffer.Length, 0);                         bool keepAlive = true;                         while (keepAlive)                        {                            if (NetduinoSocket.Poll(1, SelectMode.SelectRead))                            {                                byte[] bytes = new byte[10];                                int count = NetduinoSocket.Receive(bytes);                                 char[] chars = Encoding.UTF8.GetChars(bytes);                                string position = new string(chars, 0, count);                                Debug.Print(position);                            }                        }                    }                }            }        }    }}

Edited by Chris Walker, 29 December 2012 - 03:03 AM.
added [code][/code] tags


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 29 December 2012 - 03:06 AM

Hi rchelicopter,

 

Are you using DHCP?  If you're using DHCP, your code will start up and probably bind to your default IP address before DHCP has a chance to get an actual IP address.

 

When you're debugging from the PC, the time that it takes to attach the debugger after reboot is often long enough to get an address...in which case you wouldn't experience the issue.

 

Chris



#3 rchelicopter

rchelicopter

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Diego, Ca

Posted 29 December 2012 - 03:11 AM

Hi Chris,

Yes I'm using DHCP. When you say default IP what do you mean, is there an arbitrary address it uses?



#4 rchelicopter

rchelicopter

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Diego, Ca

Posted 29 December 2012 - 04:17 PM

Hello again,

 

I'm sorry to ask this question because I know its been asked a bit on thhis forum but I'm still having problems.

 

If I want to assign a static Ip address in 4.2 do i need to turn off DHCP in MFDeploy?  Also I've seen this code around as well

 

var interf = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

interf.EnableStaticIP("<staticIP>", "<subnetmask>", "<gateway>");

interf.EnableStaticDns(new string[] { "<primaryDNS>", "<secondaryDNS>" });

 

Can someone help me out here a bit.






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.