A lot of time, after I start my nic, I have that error every operation I try (for example a dns resolution).
I restart the project, maybe the board, and after one, two, or three times, code runs.
Any idea?
thanks
my code (the exeption is raised executing GetHostEntry, but is same if I open a socket, I try and http connection, and so on):
Dim eth1 = interfaces(0)
Dim r As New Random
Dim mac(48 - 1) As Byte ' = {&H0, &H88, &H50, m1, m2, m3}
r.NextBytes(mac)
eth1.PhysicalAddress = mac
Thread.Sleep(100)
Dim netConfiguration = _sd.GetConfigurationNetwork()
eth1.EnableStaticIP(netConfiguration.Address, netConfiguration.Subnet, netConfiguration.Gateway)
eth1.EnableStaticDns(New String() {"208.67.222.222", "208.67.220.220"})
Thread.Sleep(100)
Dim d = System.Net.Dns.GetHostEntry("www.google.com")
IsNetworkRunning = (d IsNot Nothing AndAlso d.AddressList.Length > 0)
Sleep was inserted just as test, meaning that maybe there was some delay in configuration startup in the board.
Is not important, the problem is same with or without.
What do you mean with âwork with the network up and down event handlersâ? Where are these events defined?
Private Sub NetworkAvailabilityChanged(sender As Object, e As Microsoft.SPOT.Net.NetworkInformation.NetworkAvailabilityEventArgs)
IsNetworkRunning = e.IsAvailable
If e.IsAvailable Then
NTPTime.UpdateTimeFromNTP("tempo.ien.it", 0)
Dim d = System.Net.Dns.GetHostEntry("www.google.it")
IsNetworkRunning = (d IsNot Nothing AndAlso d.AddressList.Length > 0)
End If
End Sub
The event is raised when I connect the cable, but then sometimes code go on, sometimes Iâve socket errors when I try to complete NTP or GetHostEntryâŚ
An unhandled exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.dll
Yes.
However is the NetworkAvailabilityChanged event that is raised. With the code modified Iâve this output:
Program Started
netav: 172.30.98.166
netav: 172.30.98.166
netav: 172.30.98.166
netav: 172.30.98.166
Private Sub NetworkAvailabilityChanged(sender As Object, e As Microsoft.SPOT.Net.NetworkInformation.NetworkAvailabilityEventArgs)
' IsNetworkRunning = e.IsAvailable
'If e.IsAvailable Then
' ' -- tiro su l'ora da NTP su UTC
' NTPTime.UpdateTimeFromNTP("tempo.ien.it", 0)
' ' -- testo la risoluzione DNS che servirĂ dopo per vedere se ho connettivitĂ funzionante
' Dim d = System.Net.Dns.GetHostEntry("service.cloudmo.net")
' IsNetworkRunning = (d IsNot Nothing AndAlso d.AddressList.Length > 0)
'End If
Debug.Print("netav: " & Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).IPAddress)
End Sub
Private Sub NetworkStateChanged(sender As Object, e As Microsoft.SPOT.EventArgs)
Debug.Print("ipchan: " & Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).IPAddress)
End Sub
ip and network start seems ok, are sockets that have problem