Here is a sample module i used in one of my projects....
Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Console.WriteLine(RconQuery("11.111.111.11", 20100, "myRcon", "status"))
End Sub
Friend Function RconQuery(ByVal ip As String, ByVal port As Integer, ByVal rcon As String, ByVal cmd As String) As String
Using udpClient As New UdpClient()
udpClient.Client.ReceiveTimeout = 10
Dim RemoteIpEndPoint As New Net.IPEndPoint(Net.IPAddress.Any, 0)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(String.Format("ÿÿÿÿrcon {0} {1}{2}", rcon, cmd, Chr(0)))
Dim i As Integer
For i = 0 To 3
sendBytes(i) = 255
Next
Dim sb As New StringBuilder()
Try
udpClient.Send(sendBytes, sendBytes.Length, ip, port)
WaitForPackets(sb, RemoteIpEndPoint, udpClient)
udpClient.Close()
Return sb.ToString
Catch ex As Exception 'thrown if server didnt respond after 5 sec##
Debug.WriteLine(String.Format("Exception in RconQuery: {0}{1}Details: {2}", ex.GetType, vbNewLine, ex.Message))
Return ""
End Try
End Using
End Function
Private Sub WaitForPackets(ByRef _return As StringBuilder, ByVal endpoint As Net.IPEndPoint, ByVal client As UdpClient)
While True
Try
Dim data As Byte() = client.Receive(endpoint)
_return.Append(Encoding.ASCII.GetString(data))
Catch ex As Exception
Return
End Try
End While
End Sub
End Module