Dim publisher As New Sockets.UdpClient(0)
Dim listener As New Sockets.UdpClient(3100)
Dim RemEP As IPEndPoint ' Dim RemEP As New IPEndPoint(IPAddress.Parse((TBIP.Text)), 3100) 'Dim RemEP As New IPEndPoint(IPAddress.Parse("192.168.199.253"), 3100)
Dim RemALL As New IPEndPoint(IPAddress.Any, 3100)
'** ONE DISPLAY
Private Sub BtDis_Click(sender As Object, e As EventArgs) Handles BtDis.Click
Dim sendbytes() As Byte
Dim TempString As String
Dim rcvbytes() As Byte
Dim RemEP As IPEndPoint
Static pageNumber As Integer = 1
RemEP = New IPEndPoint(TBIP.Text, 3100)
Try
TempString = ""
TempString &= TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text
TempString &= Chr(2) & TempString & Chr(3)
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemEP)
Try
If listener.Available Then
rcvbytes = listener.Receive(RemEP)
End If
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub
'** SEND TO ALL
Private Sub BtAll_Click(sender As Object, e As EventArgs) Handles BtAll.Click
Dim sendbytes() As Byte
Dim TempString As String
Static pageNumber As Integer = 1
Dim RemALL As New IPEndPoint(IPAddress.Any, 3100)
Try
TempString = ""
TempString &= TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text
TempString &= Chr(2) & TempString & Chr(3)
'TempString &= Chr(2) & TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text & Chr(3) ' STX & string & ETX //TempString = Chr(2) & TempString & Chr(3)
'TempString &= "$"
'TempString &= TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text
'TempString &= Chr(2) & TempString & Chr(3)
'TempString &= TBLine1.Text & vbCr & TBLine2.Text & vbCr & TBLine3.Text & vbCr & TBLine4.Text
'TempString &= TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemALL)
Catch ex As Exception
End Try
End Sub
'**PING
Private Sub BtPing_Click(sender As Object, e As EventArgs) Handles BtPing.Click
Dim sendbytes() As Byte
Dim TempString As String
Static pageNumber As Integer = 1
RemEP = New IPEndPoint((TBIP.Text), 3100)
TBPing.Clear()
Try
TempString = ""
TempString &= "PING"
TempString &= TempString & vbCr 'TempString &= Chr(2) & TempString & Chr(3)
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemEP)
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Clear()
listener.Client.ReceiveTimeout = 100
listener.Client.Blocking = False
End Sub
Private Sub Form1_Close(sender As Object, e As EventArgs) Handles MyBase.Closed
' listener.Close()
'listener.Client.Blocking = True
End Sub
'TIMER FOR RESPONSE
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 3100)
Dim rcvbytes() As Byte
If listener.Available Then
rcvbytes = listener.Receive(ep)
TextBox20.Text = ASCII.GetString(rcvbytes)
End If
Catch ex As Exception
End Try
End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
TBIP.Clear()
TBLine1.Clear()
TBLine2.Clear()
TBLine3.Clear()
TBLine4.Clear()
TBPing.Clear()
' TextBox20.Clear()
End Sub
Public Sub Clear()
TBIP.Clear()
TBLine1.Clear()
TBLine2.Clear()
TBLine3.Clear()
TBLine4.Clear()
TBPing.Clear()
TextBox20.Clear()
End Sub
Dim publisher As New Sockets.UdpClient(0)
Dim listener As New Sockets.UdpClient(3100)
'** ONE DISPLAY
Private Sub BtDis_Click(sender As Object, e As EventArgs) Handles BtDis.Click
Dim sendbytes() As Byte
Dim TempString As String
Dim TempIPText As String
Dim rcvbytes() As Byte
Dim RemEP As IPEndPoint
Static pageNumber As Integer = 1
'SETUP TO SEND ONLY TO 1 DISPLAY: TBIP.Text
Try
If TBIP.Text = String.Empty Then
MsgBox("A DISPLAY IP # MUST BE ENTERED", MsgBoxStyle.Critical)
Else
TempIPText = TBIP.Text
RemEP = New IPEndPoint(IPAddress.Parse(TempIPText), 3100)
TempString = ""
TempString &= vbCr & Chr(2) & TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text & Chr(3) & vbCr ' TempString &= Chr(2) & TempString & Chr(3)
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemEP)
Try
If listener.Available Then
rcvbytes = listener.Receive(RemEP)
End If
Catch ex As Exception
End Try
End If
Catch ex As Exception
End Try
End Sub
'** 'SEND TO ALL DISPLAYS - BROADCAST
Private Sub BtAll_Click(sender As Object, e As EventArgs) Handles BtAll.Click
Dim sendbytes() As Byte
Dim TempString As String
Dim rcvbytes() As Byte
Dim RemEP As IPEndPoint
Static pageNumber As Integer = 1
Try
RemEP = New IPEndPoint(IPAddress.Broadcast, 3100)
TempString = ""
TempString &= vbCr & Chr(2) & TBLine1.Text & "^40" & TBLine2.Text & "^80" & TBLine3.Text & "^120" & TBLine4.Text & Chr(3) & vbCr ' TempString &= Chr(2) & TempString & Chr(3)
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemEP)
Try
If listener.Available Then
rcvbytes = listener.Receive(RemEP)
End If
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub
'**'SEND PING TO ALL
Private Sub BtPing_Click(sender As Object, e As EventArgs) Handles BtPing.Click
Dim sendbytes() As Byte
Dim TempString As String
Dim rcvbytes() As Byte
Dim RemEP As IPEndPoint
Static pageNumber As Integer = 1
Try
RemEP = New IPEndPoint(IPAddress.Broadcast, 3100)
TempString = ""
TempString &= vbCr & Chr(2) & "PING" & Chr(3) & vbCr
If pageNumber < 255 Then pageNumber += 1 Else pageNumber = 1
sendbytes = ASCII.GetBytes(TempString)
listener.Send(sendbytes, sendbytes.Length, RemEP)
Try
If listener.Available Then
rcvbytes = listener.Receive(RemEP)
End If
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Clear()
listener.Client.ReceiveTimeout = 100
listener.Client.Blocking = False
End Sub
End Class
Dim ep As New IPEndPoint(IPAddress.Any, 0)
Dim receivingUdpClient As New UdpClient(3100)
Try
Dim rcvbytes() As Byte = receivingUdpClient.Receive(ep)
If listener.Available Then
Dim response As String = Encoding.ASCII.GetString(rcvbytes)
TextBox20.AppendText("Time: " & Now & "/" & "- IP:" & ep.Address.ToString() & "message" & rcvbytes.ToString & vbNewLine)
End If
Catch ex As Exception
End Try
- Is it doing ANYTHING?
- Is it returning a compiler error? If so, what error?
- Is it returning a runtime error? If so, what error?
- How are you sure that it is not working? UDP is a connectionless protocol, so there is no guarantee of delivery in the first place. Are you using a tool like Wireshark to see the packet leave the workstation?
Please add a bit more clarity to the question. Most of us don't mind helping (that's why we are here), but spending time to build a test environment just to try to compile and run your code is a bit out of the norm.
Another good troubleshooting tool is to add some debugging MsgBox calls to the code. This can tell you exactly where in the code it is any any point, and you can display critical variable values at that point (IP address, message text, etc.). It will help verify that the data values are what you THINK they are.