Hello,
i use the .net 4.2 Framework and the latest GHI-Firmware for my EMX.
I can’t use Sockets anymore…
I tried logging in Wireshark, but it only shows me DHCP-Leases and HTTP (using HTTPListener class)
HTTP just runs fine.
Here is the Code I’m using:
using System;
using System.Net;
using System.Net.Sockets;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
public void Connect(bool UpdateSystemTime)
{
// Resolve server address
IPHostEntry hostadd = Dns.GetHostEntry(TimeServer);
if (0 < hostadd.AddressList.Length)
{
IPEndPoint EPhost = new IPEndPoint(hostadd.AddressList[0], 123);
//Connect the time server
System.Net.Sockets.Socket TimeSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
TimeSocket.Connect(EPhost);
try
{
// Initialize data structure
Initialize();
Int32 i32DataLength = TimeSocket.Send(SNTPData, 0, SNTPData.Length, SocketFlags.None);
if (0 < i32DataLength)
{
while (true == TimeSocket.Poll(2000000, SelectMode.SelectRead))
{
i32DataLength = TimeSocket.Available;
if (0 < i32DataLength)
{
i32DataLength = TimeSocket.Receive(SNTPData, 0, i32DataLength, SocketFlags.None);
DestinationTimestamp = DateTime.Now;
System.DateTime AktuelleZeit = DateTime.Now.AddMilliseconds(LocalClockOffset);
break;
}
}
}
}
catch (SocketException e)
{
throw new Exception(e.Message);
}
finally
{
TimeSocket.Close();
}
}
}
I also tried connecting to Amazon with port 80, stream and tcp but here also nothing is sent.
The same code in .NET 4.0 on a x64 CPU runs, and Wireshark shows me NTP Packtes.
Is this a known error in netmf 4.2? Is something different in netmf 4.2?
yes I did:
Starting up the System, then wireshark shows me DHCP assignment.
hostadd[0] has the IP of the NTP-Server (I ran ping and tracert for time-a.nist.gov)
In Initialize I fill the NTP-Databytes this are 48 Byte containing the protocol (0x1B) and the current time of the EMX-RTC.
.Send sets i32DataLength to 48, so I thought data was sent, but wireshark does not display any TCP or UDP packet from the EMX (DCHP Lease)
.Poll then stays false, so nothing is incoming.
After closing the NTP Thread the HTTPListener Thread starts, that works fine, showing me HTTP packets in wireshark.
The same code on a x86 .NET 4.0 C# runs fine.
.Send sets i32DataLength to 48 and wireshark shows me the outgoing and incoming packets
.Poll gets true and i32DataLength is set to 48 from .Available
EMX-System displays EMX Version 4.2.4.0, IP-Adress from DHCP lease.
A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Net.dll
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Net.dll
OK, thanks.
The Code in the emulator runs fine, just like on the x86 code, but not on the EMX.
But the HTTPListener on EMX runs, I got no idea.
What I also found out was when using this:
Microsoft.SPOT.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new Microsoft.SPOT.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface[] ni = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
ni[0].ReleaseDhcpLease();
ni[0].RenewDhcpLease();
wireshark only tells me about the DHCP Release nothing more happens, and my EMX gets no new IP and stays on 0.0.0.0.
My DHCP-Server also does not get any new Discover or Request packet.
Without Release and Renew, the Discover and Request is sent before the code comes to:
ni[0].EnableDynamicDns();
ni[0].EnableDhcp();
I tried on static IP, but here the Sockets are not working…
It seems that everything directly using Sockets does not Send anything
Yes I tried static IP and DNS, set to the values my router sends depending on the device’s MAC-Address.
The MAC-Address should be factory default 00:21::03:00:00:01 (this is what my EMX tells me, the Label on the SOM soldered on the EMX Development board tells a different MAC) but as this MAC does not exist in my local network it should be no problem, I think.
With MFDeply the Device Capabilities tell sth. like:
Pinging... TinyCLR
[22:52:28 25.09.2012] Chk signature
Signature PASSHalSystemInfo.halVersion: 4.2.0.0
[22:52:48 25.09.2012] HalSystemInfo.halVendorInfo: Microsoft Copyright (C) Microsoft Corporation. All rig
[22:52:48 25.09.2012] ClrInfo.clrVersion: 4.2.0.0
[22:52:48 25.09.2012] ClrInfo.clrVendorInfo: Microsoft Copyright (C) Microsoft Corporation. All rig
[22:52:48 25.09.2012] ClrInfo.targetFrameworkVersion: 4.2.0.0
[22:52:48 25.09.2012] SolutionReleaseInfo.solutionVersion: 4.2.4.0
[22:52:48 25.09.2012] SolutionReleaseInfo.solutionVendorInfo: Copyright (C) GHI Electronics, LLC
[22:52:48 25.09.2012] SoftwareVersion.BuildDate: Aug 22 2012
[22:52:48 25.09.2012] SoftwareVersion.CompilerVersion: 410462
That was what I did.
I also used MFDeploy and disabled DHCP used a fixed IP and DNS.
But both did not help me.
What I found:
the socket has a Local Endpoint Property, this is always 0.0.0.0 followed by a Port Number.
In x86 .NET 4.0 it’s my Computer’s IP.
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface[] ni = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
ni[0].IPAddress
is 192.168.197.68 what was my DHCP value and my fixed IP setting.
But still HTTP runs, even through/behind my Router
but the LocalEndPoint is read onyl, how can I set it?
4.2
On an EMX Development Board Version 1.3
[22:52:48 25.09.2012] ClrInfo.targetFrameworkVersion: 4.2.0.0
[22:52:48 25.09.2012] SolutionReleaseInfo.solutionVersion: 4.2.4.0
on x86 it’s 4.0
(
I’m also 99% shure it ran under dotNET Micro Framework < 4.0
But here i do not have SQLite and SSL shoud run on 4.2, as I need SSL and SQLite I must use 4.2
)
System.Net.Sockets.Socket TimeSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface[] ni = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
IPEndPoint EPMe = new IPEndPoint(IPAddress.Parse(ni[0].IPAddress), 123);
TimeSocket.Connect(EPhost);
...
i32DataLength = TimeSocket(SNTPData, 0, SNTPData.Length, SocketFlags.None);
-> Socket.LocalEndPoint = 0.0.0.0
System.Net.Sockets.Socket TimeSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface[] ni = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
IPEndPoint EPMe = new IPEndPoint(IPAddress.Parse(ni[0].IPAddress), 123);
TimeSocket.Bind(EPMe);
...
i32DataLength = TimeSocket.SendTo(SNTPData, 0, SNTPData.Length, SocketFlags.None, EPhost);
-> Socket.LocalEndPoint = MyIP
-> Socket.RemoteEndPoint = NTP-ServerIP
But in Wireshark Destination = 0.0.0.0
So It looks like either Source or Destination is always 0.0.0.0
But in x86 dotNET and in the Emulator the Source and Destination IP is correct.
So with 4.2 there might be a problem with a register of the MII/RMII on SMSC PHY or the NXP ARM, as the compiled TCP/IP Stack should be the same on x86 dotNET, Emulator dotNET Micro and EMX dotNet Micro?
Here StaticIP or DHCP seems making no difference.
But I still can not figure out why the HTTPListener-Class runs correctly, maybe this is not built with dotNET Sockets?
Could my EMX have a defect, or could you retrace my issue?
Why don’t you step back to 4.1 (load 4.1 firmware and create new project targeting 4.1) and see if the same problem exists or if your code just works as you expect. That will help GHI eliminate other portions of the problem.
Also, your comments about bigdotnet probably aren’t adding too much… there are things that are different so lets focus on what 4.1/4.2 netmf does different amongst themselves.
@ Nokill - I am trying to help you but I am confused about what the problem is. .NET Micro Framework is not 100% like .NET Framework so I suggest that you start with the sample code provided by Microsoft :
For example they got an HttpServer sample code and they yse this to get the local IP address.
IPAddress ip = IPAddress.GetDefaultLocalAddress();
HTTP runs…
I used the SocketClient form the Examples.
This one creates a TCP Socket on Port 80
// Create socket and connect to the server's IP address and port
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(hostEntry.AddressList[0], port)); <- "amazon.com" port 80
In this socket no endpoint is 0.0.0.0 and it connects fine.
Then I added an UDP socket like this:
// Create socket and connect to the server's IP address and port
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.Connect(new IPEndPoint(hostEntry.AddressList[0], 123)); <- "time-a.nist.gov" port 123
here LocalEndpoint is 0.0.0.0 and nothing is send or received (at least Wireshark is telling me no packet goes out)
Is there any speciallity about Dgram, Udp?
I double checket my router, no packet filtering is active.