UDP question

brudvik

Member
Joined
May 16, 2006
Messages
5
Programming Experience
10+
Hi, and first of all I'd like to say congratulations to whomever is responsible
for this forum. It contain quite a bit of good and valuable information and
I'll most certainly be a frequent visitor here.

I am currently working on a project (similar to gamespy and other game
server monitors a like) to aquire game server information from unreal engine
based games. This is done by making a UDP connection to the game server,
sending a command string, and reading the reply. So far so good, and the
first draft works - well works in the term that it works for lesser servers.

The moment a server starts to have more than 14 players, the returned
reply is too big to be handled it appears. And after doing some reading up
on the UDP protocol and such, I've come to the conclusion that it most
likely is sending several packets, and I am only managing to pick up the first
one.

Below is a snippet of the class that currently sends and reads UDP replies.
VB.NET:
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading

Public Class clsUDPContentHandler

    Private strHostname As String
    Private intPort As Integer
    Private udpClient As New UdpClient

    Public Event udpSocketError(ByVal description As String)
    Public Event udpDataArrival(ByVal data As String)

    Public Property hostname() As String
        Get
            Return (strHostname)
        End Get
        Set(ByVal Value As String)
            strHostname = Value
        End Set
    End Property

    Public Property port() As Integer
        Get
            Return (intPort)
        End Get
        Set(ByVal Value As Integer)
            intPort = Value
        End Set
    End Property

    Public Sub New()
    End Sub

    Public Sub New(ByVal hostname As String, ByVal port As Integer)
        strHostname = hostname
        intPort = port
    End Sub

    Public Sub udpSendCommand(ByVal command As String)
        Try
            udpClient.Connect(strHostname, intPort)
            Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(command)
            udpClient.Send(sendBytes, sendBytes.Length)
            Call udpRecieveData(udpClient)
        Catch ex As Exception
            RaiseEvent udpSocketError(ex.ToString)
        End Try
    End Sub

    Private Sub udpRecieveData(ByVal udpServer As UdpClient)
        Try
            udpServer.DontFragment = True
            udpServer.Client.ReceiveBufferSize = 28192
            Dim clsCommon As New clsCommonFunction
            Dim udpRemoteIPEndPoint As New IPEndPoint(IPAddress.Any, 0)
            Dim udpRecievedBytes As Byte() = udpServer.Receive(udpRemoteIPEndPoint)
            Dim udpRecievedData As String = clsCommon.byteToString(udpRecievedBytes)
            RaiseEvent udpDataArrival(udpRecievedData)
            If Not udpRecievedData.Contains("\final\") Then
                MsgBox("missing values..")
            End If
        Catch ex As Exception
            RaiseEvent udpSocketError(ex.ToString)
        End Try
    End Sub

End Class
The command it refers to can be a wide range of different commands
but I've mostly been using the "command" \status\ as it's a command
that returns most of the game information that I require. Information
like map name, players, statistics and more. If you want to test it out
then put the above code in a classfile, change the line that reads:

VB.NET:
Dim udpRecievedData As String = clsCommon.byteToString(udpRecievedBytes)
And change that particular line to:

VB.NET:
Dim udpRecievedData As String = System.Text.Encoding.ASCII.GetString(udpServer.Receive(udpRemoteIPEndPoint))
And call it by issuing the hostname: 66.102.113.180 and port 1717.
It's an american game server for the game "Americas Army". If the server
contains few players it will return them and the final entry element
which should read \final\ - if on the other hand the amount of players
are too many, the reply will be cut.

A typical reply could look like this:

\hostname\[VoN] Vikings of Norway\gamename\armygame\gamever\2.6.0\hostport\1716\mapname\Collapsed Tunnel\gametype\AAGP_GameTeamObjective\numplayers\0\numteams\2\maxplayers\14\gamemode\openplaying\password\1\tour\3\official\1\leased\1\nato\0\miles\0\cheats\0\minhonor\1\maxhonor\100\groups\ALL\current_round\0/12\mission_time\6:22\sv_punkbuster\1\tournament\0\ultimate_arena\0\thirdparty\0\custom\0\AdminName\[VoN]complex\AdminEMail\complex@vikingsofnorway.com\score_t0\0\score_t1\0\final\\queryid\1.1
Basically I need some guiding pointers here on how to approach this,
been trying several approaches, and the only approach I can think of
that might be working, is to manage to read all the packets somehow.
Any suggestions is appreaciated.
 
Back
Top