Hi
I'm working on a messenger that uses UDP and i can send a message once alright, but when i try and send a second message i get an error "An invalid argument was supplied" for this line
SendUdp.JoinMulticastGroup(GroupIP, 12)
I have no idea why this is happening (not that i know that much about udp anyway), so if anyone could help out that would be well appreciated. Thanks.
This is called when enter key is pressed
Private Sub UDPSend()
GroupIP = IPAddress.Parse("224.0.0.0")
GroupEP = New IPEndPoint(GroupIP, 2056)
SendUdp.JoinMulticastGroup(GroupIP, 12) 'error happening here 2nd time through
Dim bteSendDate() As Byte
Try
bteSendDate = Encoding.Unicode.GetBytes(rtb_MessageWrite.Text)
SendUdp.Send(bteSendDate, bteSendDate.Length, GroupEP)
Catch ex As Exception
rtb_MessageView.Text = rtb_MessageView.Text & (ex.Message)
End Try
End Sub
This is on a new thread
Private Sub BeginListen()
Dim bteReceiveData() As Byte
Dim strReceiveData As String
GroupIP = IPAddress.Parse("224.0.0.0")
GroupEP = New IPEndPoint(GroupIP, 2056)
ListenUdp = New UdpClient(2056)
ListenUdp.JoinMulticastGroup(GroupIP)
Do
bteReceiveData = ListenUdp.Receive(GroupEP)
strReceiveData = Encoding.Unicode.GetString(bteReceiveData)
If rtb_MessageView.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {strReceiveData})
Else
rtb_MessageView.Text = rtb_MessageView.Text & strReceiveData
End If
Loop
End Sub
Private Delegate Sub SetTextCallback(ByVal a As String)
Private Sub SetText(ByVal [text] As String)
rtb_MessageView.Text = rtb_MessageView.Text & [text]
End Sub