Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The UDP client sends an array of bytes.<br> You could use a memory stream and write bytes to an array. </p> <pre><code>Public Class MainClass Shared client As UdpClient Shared receivePoint As IPEndPoint Public Shared Sub Main() receivePoint = New IPEndPoint(New IPAddress(0), 0) client = New UdpClient(8888) Dim thread As Thread = New Thread(New ThreadStart(AddressOf WaitForPackets)) thread.Start() Dim packet As Packet = New Packet("client") Console.WriteLine("Sending packet containing: ") Dim data As Byte() = packet.Data client.Send(data, data.Length, "localhost", 5000) Console.WriteLine("Packet sent") End Sub Public Shared Sub WaitForPackets() While True Dim data As Byte() = client.Receive(receivePoint) Console.WriteLine("Packet received:" &amp; _ vbCrLf &amp; "Length: " &amp; data.Length &amp; vbCrLf &amp; _ System.Text.Encoding.ASCII.GetString(data)) End While End Sub ' WaitForPackets End Class Public Class Packet Private _message As String Public Sub New(ByVal message As String) _message = message End Sub Public Function Data() As Byte() Dim ret(13 + _message.Length) As Byte Dim ms As New MemoryStream(ret, True) ms.WriteByte(&amp;H1) '&lt;0x01&gt;Z30&lt;0x02&gt;AA&lt;0x06&gt;&lt;0x1B&gt;0b&lt;0x1C&gt;1&lt;0x1A&gt;1This message will show up on the screen&lt;0x04&gt; ms.Write(System.Text.Encoding.ASCII.GetBytes("Z30"), 0, 3) ms.WriteByte(&amp;H2) ms.Write(System.Text.Encoding.ASCII.GetBytes("AA"), 0, 2) ms.WriteByte(&amp;H6) ms.Write(System.Text.Encoding.ASCII.GetBytes("0b"), 0, 2) ms.WriteByte(&amp;H1C) ms.Write(System.Text.Encoding.ASCII.GetBytes("1"), 0, 1) ms.WriteByte(&amp;H1A) ms.Write(System.Text.Encoding.ASCII.GetBytes(_message), 0, _message.Length) ms.WriteByte(&amp;H4) ms.Close() Data = ret End Function End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload