I have done what you're saying haven't I? Anyway I commented the BindTo line out and it works now.
The code:
Quote:Try Do While okToBroadcast = True Dim s1 As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) Dim broadcast As IPAddress = IPAddress.Parse("255.255.255.255") Dim sendbuf As Byte() = Encoding.ASCII.GetBytes("test") Dim ep As New IPEndPoint(broadcast, 11000) s1.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1) 's1.Bind(ep) s1.SendTo(sendbuf, ep) rxtChat.AppendText(Chr(13) & "Broadcasting Game on Local Network.") Loop Finally End Try |
Thanks for your help btw, at least I got it solved :D (rating points for you)
But yeah I have a problem with the code that receives the broadcast, you see if you goto the form once it will work perfectly, if you hide the form then show it again it generates this exception:
Quote:An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll
Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted |
I know it's because each time it shows the form it tries to create the socket but it hasnt been disposed of, thing is I don't know how to dispose it properly. I've tried mySocket.Close() when the form is closed/hidden, but it doesn't work, please help.
Edit: I did some testing and it seems this exception does not matter, the udpclient socket will still receive the broadcast, so I just Catch it now and do nothing for it.
[Edited by - Kurt69 on June 30, 2006 1:27:41 AM]