Hi all I'm am trying to do sum custom events in a Class. My class listens for a UDP Broadcast, I want to Raise and Event when a message is received to display the message from a windows form. I am having no luck. Can sum one help.
Here is my code.
Form CodeCode:Public Class UDP_Broadcast Public Event NewMessage(ByVal Message As String) Public Port As Integer = 2456 Public Sub Receiver_Load() Dim t As New Threading.Thread(AddressOf listen) t.IsBackground = True t.Start() End Sub Public Sub Receiver_Closing() If udp IsNot Nothing Then udp.Close() End Sub Private udp As Net.Sockets.UdpClient Private Sub listen() Try udp = New Net.Sockets.UdpClient(Port) udp.EnableBroadcast = True Dim ep As New Net.IPEndPoint(Net.IPAddress.Broadcast, Port) Do Dim b() As Byte = udp.Receive(ep) 'Me.Invoke(safeAddText, System.Text.Encoding.UTF32.GetString(b)) safeAddText(System.Text.Encoding.UTF32.GetString(b)) Loop Catch ex As Exception If udp IsNot Nothing Then udp.Close() End Try End Sub Private Delegate Sub delAddText(ByVal text As String) Private safeAddText As New delAddText(AddressOf AddText) Private Sub AddText(ByVal text As String) RaiseEvent NewMessage(text) 'MsgBox(text) End Sub End Class
Code:Private WithEvents Mess As UDP_Broadcast Private Sub UDP_Broadcast1(New_UDP_Mess As String) Handles Mess.NewMessage MsgBox(New_UDP_Mess) End Sub


Reply With Quote


