General Problem UDP receive

kurt69

Well-known member
Joined
Jan 17, 2006
Messages
78
Location
Australia
Programming Experience
Beginner
Hi, got a general problem here, not sure how to fix it.. i've hardly dealt with this sought of stuff before.

So I have this UDP broadcasting feature in my application right, it has both the send and receive code built in. Now it's the receive code I'm having trouble with. What I want it to do is to store the receive data (which is a string) in a listbox, while storing the IPEndPoint that sent the data in an array. Here's what I have so far:

VB.NET:
Try
            Dim listener As New Sockets.UdpClient(11000)
            Dim anyEP As New IPEndPoint(IPAddress.Parse("0.0.0.0"), 11000)
            lstHostlist.Items.Insert(0, "Waiting for broadcast")
            Do While Not done
                Dim rcvdHost As Byte() = listener.Receive(anyEP)
                Dim h As Integer
                Dim hostIP As String = anyEP.ToString
                For h = 0 To UBound(hostsBd)
                    If hostsBd(h) = hostIP Then
                        hostsBd(h + 1) = hostIP
                        lstHostlist.Items.Add(Encoding.ASCII.GetString(rcvdHost, 0, rcvdHost.Length))
                    End If
                Next
            Loop
        Finally
        End Try

Also how can I split anyEP.ToString. For example say it is equal to 10.1.1.2:1880 and I only want the 10.1.1.2. THANKS IN ADVANCED BIG TIME!!!!
 
I had a feeling this would get moved, umm my main question is not about Net/Sockets, it is about variables and arrays. While my 2nd question I can most likely work out for myself.

Not being an ass but just out of curiousity whoever moved this, did you even read it first or just look at the title?
 
kurt69 said:
storing the IPEndPoint that sent the data in an array.
Is the above quote your question?? If so, then you get the Address property of IPEndPoint and store it in an array or preferably an IPEndpoint collection.
 
Ah sorry about my poor explanation, it was late when i wrote that. Anyway I'm trying to only get it to check if the host has already sent data to that port and if it has then just do nothing, otherwise store the ipendpoint (as a string which i want to split and remove the port part of it) in an array while displaying the received bytes in the listbox (but only once, not infinite copies).

How do I do this?? thanks, once again sorry
 
Will this do what I want (I don't have the chance to test it atm.):
VB.NET:
Do While Not done
                Dim rcvdHost As Byte() = listener.Receive(anyEP)
                Dim h As Integer
                Dim hostIP As String = anyEP.ToString
                For Each hostsBd In hostsBd(h)
                    If hostsBd(h) = hostIP Then
                        lstHostlist.Items.Insert(h, Encoding.ASCII.GetString(rcvdHost, 0, rcvdHost.Length))
                    Else
                        hostsBd(h + 1) = hostIP
                        lstHostlist.Items.Insert(h, Encoding.ASCII.GetString(rcvdHost, 0, rcvdHost.Length))
                    End If
                Next
            Loop
 
Back
Top