mebjen
asked on
'URGENT' - Unreachable Host Error -
GURU's,
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.Inter Network, SocketType.Dgram, ProtocolType.Udp)
s.SetSocketOption(SocketOp tionLevel. IP, SocketOptionName.AddMember ship, New MulticastOption(ip))
s.SetSocketOption(SocketOp tionLevel. IP, SocketOptionName.Multicast TimeToLive , 255)
Dim b As Byte()
b = Encoding.ASCII.GetBytes(me ssage)
Dim ipep As IPEndPoint = New IPEndPoint(IPAddress.Parse (mcastGrou p), port)
s.Connect(ipep)
s.Send(b, b.Length, SocketFlags.None)
s.Close()
End Sub
Sub htIDBroadCast()
Dim hostIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByNa me(System. Net.Dns.Ge tHostName)
Dim hostName As System.Net.IPHostEntry = System.Net.Dns.GetHostByAd dress(host IP.Address List(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)
Try
'//07-07 Broadcast ID every 5 seconds on port 5000
Do
broadCastHTID("255.255.255 .255", 5000, pcId) 'for release use ip 255.255.255.255 to broadcast over network
Thread.Sleep(5000)
Console.WriteLine("BroadCa st Message sent from " + pcID) 'for debug
Loop
Catch socketEx As SocketException
Call handleExc("htIDBroadCast_S ocketExcep tion", socketEx)
Catch ex As Exception
Call handleExc("htCommunication s", ex)
Finally
End Try
End Sub
Thanks in advance
MB
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.Inter
s.SetSocketOption(SocketOp
s.SetSocketOption(SocketOp
Dim b As Byte()
b = Encoding.ASCII.GetBytes(me
Dim ipep As IPEndPoint = New IPEndPoint(IPAddress.Parse
s.Connect(ipep)
s.Send(b, b.Length, SocketFlags.None)
s.Close()
End Sub
Sub htIDBroadCast()
Dim hostIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByNa
Dim hostName As System.Net.IPHostEntry = System.Net.Dns.GetHostByAd
Dim trkId As String = hostName.HostName.ToString
'Broadcast pcID - which is from the config(row 0) and is set to pc (HT device name)
Try
'//07-07 Broadcast ID every 5 seconds on port 5000
Do
broadCastHTID("255.255.255
Thread.Sleep(5000)
Console.WriteLine("BroadCa
Loop
Catch socketEx As SocketException
Call handleExc("htIDBroadCast_S
Catch ex As Exception
Call handleExc("htCommunication
Finally
End Try
End Sub
Thanks in advance
MB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you running the Windows application on the same machine as the Console App?
J
J
One other question, I see you calling htIDBroadCast and sending it your pcID, but where are you setting the pcID?
J
J
OK... I think your remark tells me you have a config array, where you are setting static values?
J
J
ASKER
J,
>> Are you running the Windows application on the same machine as the Console App?
NO -
>> One other question, I see you calling htIDBroadCast and sending it your pcID, but where are you setting the pcID?
Dim hostIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByNa me(System. Net.Dns.Ge tHostName)
Dim hostName As System.Net.IPHostEntry = System.Net.Dns.GetHostByAd dress(host IP.Address List(0))
Dim pcID As String = hostName.HostName.ToString
>> OK... I think your remark tells me you have a config array, where you are setting static values?
In a byte array
MB
>> Are you running the Windows application on the same machine as the Console App?
NO -
>> One other question, I see you calling htIDBroadCast and sending it your pcID, but where are you setting the pcID?
Dim hostIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByNa
Dim hostName As System.Net.IPHostEntry = System.Net.Dns.GetHostByAd
Dim pcID As String = hostName.HostName.ToString
>> OK... I think your remark tells me you have a config array, where you are setting static values?
In a byte array
MB
Ok.. I have to run for a while... if someone else doesn't help with this part I will be back around 2pm Est. time... in the states.
J
J
ASKER
J,
I have been able to correct the broadCast problem by doing a thread.sleep(500) in the socketException - somehow this is all thats needed, so that when the windows app joins the network again - the console app broadcasts its ID - not 'localHost'.
Thanks for all your help.
MB
I have been able to correct the broadCast problem by doing a thread.sleep(500) in the socketException - somehow this is all thats needed, so that when the windows app joins the network again - the console app broadcasts its ID - not 'localHost'.
Thanks for all your help.
MB
That is cool, good catch, by letting the thread sleep until you reconnect you arent closing it which is what was causing your problem. The alternative was to reset everything upon reconnection, just as if the app was started up again.
J
J
ASKER
OK - it makes sense - and it works to a point. When the console app is first started it's broadcasting its ID (lets say ht3234), and the windows app see's the broadcast. Then I drop the windows app off the network - and the console app nows this and using a goTo line statement the console app starts displaying on the screen "Trying To Connect" -
OK - so now I bring the windows app back on - and the console app sees that it has something to connect with - it begins broadcasting again -
But now the broadcast is 'localhost' not ht3234.
mb