'URGENT' - Unreachable Host Error -
Posted on 2004-08-17
I have a VB .NET console app (vs 2003), that broadcasts its ID every 5 seconds - and a VB .NET Windows App (vs 2003) that listens for that broadcast.
Now, when I test this via ethernet or D-Link (wi-fi) every thing works fine as long as there is other members on the network.
But when no one else is on the network - I receive the following:
'A Socket Operation Was Attempted To An Unreachable Host.' and the broadcasts stop.
My goal was to have the console app broadcasting its ID whether there was anybody on the network or not - and if no one was there that would be OK - but when someone got into range (wireless) - they would see the console app broadcasting its ID. - Actually I did a range test - and when I moved out of range and then came back into range everything was fine. Its when I 'shutdown' the Windows App - that the console app generates the error and stops broadcasting. Or if I start the console app - and no one else is on the network.
Could someone please show me the error in my ways - and show me how to achieve my goal.
(Broadcast Code from ConsoleApp)
Private Sub broadCastHTID(ByVal mcastGroup As String, ByVal port As Integer, ByVal message As String)
Dim ip As IPAddress = IPAddress.Parse(mcastGroup)
Dim s As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, New MulticastOption(ip))
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 255)
Dim b As Byte()
b = Encoding.ASCII.GetBytes(message)
Dim ipep As IPEndPoint = New IPEndPoint(IPAddress.Parse(mcastGroup), port)
s.Send(b, b.Length, SocketFlags.None)
Dim hostIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
Dim hostName As System.Net.IPHostEntry = System.Net.Dns.GetHostByAddress(hostIP.AddressList(0))
Dim trkId As String = hostName.HostName.ToString
'Broadcast pcID - which is from the config(row 0) and is set to pc (HT device name)
'//07-07 Broadcast ID every 5 seconds on port 5000
broadCastHTID("255.255.255.255", 5000, pcId) 'for release use ip 255.255.255.255 to broadcast over network
Console.WriteLine("BroadCast Message sent from " + pcID) 'for debug
Catch socketEx As SocketException
Call handleExc("htIDBroadCast_SocketException", socketEx)
Catch ex As Exception
Call handleExc("htCommunications", ex)
Thanks in advance