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.

AxelG's Content

There have been 52 items by AxelG (Search limited from 27-April 23)


By content type

See this member's


Sort by                Order  

#29505 First chance Socket Exception on socket.Accept()

Posted by AxelG on 22 May 2012 - 02:35 AM in Netduino Plus 2 (and Netduino Plus 1)



Sometimes, Socket.Accept will throw an Exception. It's only sometimes, and it's immediately after the program starts.

I do have a busy loop in to wait for an IP to be assigned, but otherwise I can't figure out what going on here. Ideas?



Chris:
The only way I can get Sockets to work is to catch the 10053 exception, sleep for 100ms and immediately try again. Sometimes it works on second or third try; sometimes more. I am not sure you are getting the same error code; can you post the debug?



#29351 DHCP issues with Netduino Plus

Posted by AxelG on 17 May 2012 - 10:06 PM in Beta Firmware and Drivers

Hoping to keep the discussion moving on the socket-related questions. I am new to the Netduino Plus with about 2 weeks under my belt of playing with it. A lot of my time is spent in .NET Visual Studio Emulator mode and moving to the hardware when I need to work on the hardware integration parts. I have noticed a few quirks with various differences between emulator and hardware deployed versions; this socket problem is one I am playing with and have not found a reliable workaround; yet. I reset all of my networking settings to static IP through MFDeploy.exe, and make my router aware of the NDP MAC address and reserved IP address; until I get a successful network ping on that static IP address. This sometimes takes a couple router resets to get right so Netduino responds to a ping. I am running a "tried-and-true" windows socket service on port 8484 on a completely different server. It is a basic service listening on port 8484 for a simple "HELLO" to come across the Tcp socket. The following snippet of a program works fine in emulator mode and I can connect 100% of the time. When I deploy to the hardware; no good. It sometimes connects, and generally stays connected; but when it fails to connect - forget it. It just keeps timing out. (this code is in a loop that keeps trying to connect until it does in the "real" software) I am including code and the associated debug output. Any insight on what I can try next would be helpful. Oh, I flashed to 4.1.1 from 4.1.0.6 and fixed my SD card issues; but seemed to make this issue worse (but I may have just been tired and hopped up on Coke Zero...) I have not tried 4.2 yet. -->(snip)<-- public class Program { public static void Main() { int port = 8484; string server = "192.168.5.102"; ShowNetworks(); try { Debug.Print("Defininig new socket "); Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Debug.Print("Defininig new static endpoint and connecting to "+ server + "on port " + port.ToString()); IPHostEntry hostEntry = Dns.GetHostEntry(server); serverSocket.Connect(new IPEndPoint(hostEntry.AddressList[0], port)); Debug.Print("Sending a HELLO statemnt to the waiting service"); Byte[] bytesToSend = Encoding.UTF8.GetBytes("HELLO\n" + "12345678910\n"); serverSocket.Send(bytesToSend, bytesToSend.Length, 0); } catch (SocketException se) { Debug.Print("SocketException when connecting to " + server + "."); Debug.Print("Socket Error Code: " + se.ErrorCode.ToString()); Debug.Print(se.ToString()); } } private static void ShowNetworks() { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { int i = 0; foreach (string s in adapter.DnsAddresses) { i++; Debug.Print("DNS Address : " + s); } if (i == 0) Debug.Print("No DNS Address"); Debug.Print("Default Gateway: " + adapter.GatewayAddress); Debug.Print("IP Address : " + adapter.IPAddress); Debug.Print("Is DHCP Enabled: " + adapter.IsDhcpEnabled); Debug.Print("Is Dynamic DNS : " + adapter.IsDynamicDnsEnabled); Debug.Print("Interface Type : " + adapter.NetworkInterfaceType.ToString()); Debug.Print("MAC Address : " + ToHexString(adapter.PhysicalAddress)); Debug.Print("SubnetMask : " + adapter.SubnetMask + "\n"); } } } -->(Debug Output)<-- No DNS Address Default Gateway: 192.168.5.1 IP Address : 192.168.5.50 Is DHCP Enabled: False Is Dynamic DNS : False Interface Type : 6 MAC Address : 5C-86-4A-00-4F-1D SubnetMask : 255.255.255.0 Defininig new socket Defininig new static endpoint and connecting to 192.168.5.102on port 8484 #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) #### #### Message: #### Microsoft.SPOT.Net.SocketNative::connect [IP: 0000] #### #### System.Net.Sockets.Socket::Connect [IP: 001d] #### #### NetduinoPlusApplication1.Program::Main [IP: 0044] #### #### SocketException ErrorCode = 10053 #### SocketException ErrorCode = 10053 A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll #### SocketException ErrorCode = 10053 #### SocketException ErrorCode = 10053 SocketException when connecting to 192.168.5.102. Socket Error Code: 10053 System.Net.Sockets.SocketException The thread '<No Name>' (0x1) has exited with code 0 (0x0). Done. Waiting for debug commands... The program '[3] Micro Framework application: Managed' has exited with code 0 (0x0).




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.