Jump to content

UDPRecv


Recommended Posts

Im having a problem with the UDPRecv function. I send a query to a server and the server replies only the part before the first space (hex character 20) of the packet. For some reason it does not parse the part after it. The packet sniffer does show the entire packet, so it's clearly something that goes wrong with UDPRecv here.

Is anyone experiencing something similar?

Regards,

- FMX

Link to comment
Share on other sites

Im having a problem with the UDPRecv function. I send a query to a server and the server replies only the part before the first space (hex character 20) of the packet. For some reason it does not parse the part after it. The packet sniffer does show the entire packet, so it's clearly something that goes wrong with UDPRecv here.

Is anyone experiencing something similar?

Regards,

- FMX

<{POST_SNAPBACK}>

i actually haven't played with this at all, but think i will now that i know it's there and i'll let you know if i see similar issues.
Link to comment
Share on other sites

Im having a problem with the UDPRecv function. I send a query to a server and the server replies only the part before the first space (hex character 20) of the packet. For some reason it does not parse the part after it. The packet sniffer does show the entire packet, so it's clearly something that goes wrong with UDPRecv here.

Is anyone experiencing something similar?

code would help.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Alright I get an update on the situation. It seems to be related to the handling of the NULL character in AutoIt. (Thanks dev)

Anyone has experience with this character?

<{POST_SNAPBACK}>

as he pointed out, your source would be very helpful in recreating the error and troubleshooting...
Link to comment
Share on other sites

You're right. The script is for querying a gameserver.

I set up a random one in the script.

#include <string.au3>
#include <array.au3>

UDPStartup()

$socket = UDPOpen("82.133.85.17", 27025)
If @error <> 0 Then Exit

$infostring = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00"

    UDPSend($socket, _HexToString($infostring))
    sleep(200)
    $data = UDPRecv($socket, 200)
   
    If $data <> "" Then
        MsgBox(0, "Query results", $data)
    EndIf
    Sleep(100)

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

The output AutoIt gives:

ÿÿÿÿIjolt.co.uk - (14) CSS - cs_assault Only

Here the sniffer data, which shows there is more than just the part before the NULL char.

FF FF FF FF 49 07 6A 6F 6C 74 2E 63 6F 2E 75 6B  ....I.jolt.co.uk
20 2D 20 28 31 34 29 20 43 53 53 20 2D 20 63 73   - (14) CSS - cs
5F 61 73 73 61 75 6C 74 20 4F 6E 6C 79 00 63 73  _assault Only.cs
5F 61 73 73 61 75 6C 74 00 63 73 74 72 69 6B 65  _assault.cstrike
00 43 6F 75 6E 74 65 72 2D 53 74 72 69 6B 65 3A  .Counter-Strike:
20 53 6F 75 72 63 65 00 F0 00 0F 10 00 64 6C 00   Source......dl.
01 31 2E 30 2E 30 2E 32 32 00                   .1.0.0.22.
Edited by FrashMX
Link to comment
Share on other sites

You're right. The script is for querying a gameserver.

I set up a random one in the script.

#include <string.au3>
#include <array.au3>

UDPStartup()

$socket = UDPOpen("82.133.85.17", 27025)
If @error <> 0 Then Exit

$infostring = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00"

    UDPSend($socket, _HexToString($infostring))
    sleep(200)
    $data = UDPRecv($socket, 200)
   
    If $data <> "" Then
        MsgBox(0, "Query results", $data)
    EndIf
    Sleep(100)

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

The output AutoIt gives:

ÿÿÿÿIjolt.co.uk - (14) CSS - cs_assault Only

Here the sniffer data, which shows there is more than just the part before the NULL char.

FF FF FF FF 49 07 6A 6F 6C 74 2E 63 6F 2E 75 6B  ....I.jolt.co.uk
20 2D 20 28 31 34 29 20 43 53 53 20 2D 20 63 73   - (14) CSS - cs
5F 61 73 73 61 75 6C 74 20 4F 6E 6C 79 00 63 73  _assault Only.cs
5F 61 73 73 61 75 6C 74 00 63 73 74 72 69 6B 65  _assault.cstrike
00 43 6F 75 6E 74 65 72 2D 53 74 72 69 6B 65 3A  .Counter-Strike:
20 53 6F 75 72 63 65 00 F0 00 0F 10 00 64 6C 00   Source......dl.
01 31 2E 30 2E 30 2E 32 32 00                    .1.0.0.22.

<{POST_SNAPBACK}>

it seems like it's just seeing it as a null terminated string... logical assumption usually, but not here i guess. one thing you could do is make a second (or more if there is more than one null in the string you're trying to receive) variable, $data2 or something that is assigned a value right after $data, it should pick up the next section after the null (or the null in which case you'd have to make a third to catch the next part probably) and then concatenate them, and work with that string as the full string...
Link to comment
Share on other sites

it seems like it's just seeing it as a null terminated string... logical assumption usually, but not here i guess. one thing you could do is make a second (or more if there is more than one null in the string you're trying to receive) variable, $data2 or something that is assigned a value right after $data, it should pick up the next section after the null (or the null in which case you'd have to make a third to catch the next part probably) and then concatenate them,  and work with that string as the full string...

<{POST_SNAPBACK}>

Valik says pertinent stuff maybe that helps? granted he's talking about reading from a file, but essentially reading is reading... i still think my solution would work...
Link to comment
Share on other sites

Well I dropped Larry a PM asking if he could add a switch to UDPRecv/TCPRecv to receive the data in hex. In that case the problem wouldn't be there :whistle:

Any idea how I would assign a second variable to the stuff after the NULL char?

Link to comment
Share on other sites

Any idea how I would assign a second variable to the stuff after the NULL char?

<{POST_SNAPBACK}>

sure thing, here's some slightly modified code...

#include <string.au3>
#include <array.au3>

UDPStartup()

$socket = UDPOpen("82.133.85.17", 27025)
If @error <> 0 Then Exit

$infostring = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00"

    UDPSend($socket, _HexToString($infostring))
    sleep(200)
    $data = UDPRecv($socket, 200)
    $data2 = UDPRecv($socket, 200-StringLen($data))
    $data = $data & $data2    
If $data <> "" Then
        MsgBox(0, "Query results", $data)
    EndIf
    Sleep(100)

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

all it's doing is another read, then concatenating the strings, nothing too spectacular... lemme know if that gets what you want it to

***edit***

had tried to bold some code, didn't work out, this is all i added:

$data2 = UDPRecv($socket, 200-StringLen($data))
    $data = $data & $data2
Edited by cameronsdad
Link to comment
Share on other sites

Doesn't seem to work somehow. Thanks alot for trying though.

<{POST_SNAPBACK}>

It can't work, as there is a NULL char in the string. This is an "end of string" marker in C and C++. Every function that relies on the standard C/C++ libs will stop further reading the string as soon as the first NULL char appears. Unfortunately there is nothing you can do about it.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

It can't work, as there is a NULL char in the string. This is an "end of string" marker in C and C++. Every function that relies on the standard C/C++ libs will stop further reading the string as soon as the first NULL char appears. Unfortunately there is nothing you can do about it.

Cheers

Kurt

<{POST_SNAPBACK}>

right, so the null is caught in the attempt to readin in $data, then $data2 should get the rest, or if not, then $data2 should capture the null right? so a $data3 should be able to get the rest of the string until the next null right? maybe change

$data = UDPRecv($socket, 200)
$data2 = UDPRecv($socket, 200-StringLen($data))
$data = $data & $data2

to read

[code]
$data = UDPRecv($socket, 200)
$data2 = UDPRecv($socket,1)
$data3 = UDPRecv($socket, 200- (StringLen($data) +1))
$data = $data & $data3
Link to comment
Share on other sites

As AutoIt does not support binary data,,, u outta luck... try

UDPRecv($socket, 1)

and build your string a character at a time... poor speed , but theoretically possible...

Lar.

<{POST_SNAPBACK}>

wouldn't adding the UDPRecv($socket, 1) after the truncated string to absorb the null, then grabbing the next set (as in my example) effectively do the same thing if it's just a single string with a single Null in it? And as this is coming in as an automatic response, seems like the appearance of nulls in the string would be at regular intervals, or atleast have a set frequency, meaning if there is only one null in the string he wants this time, there should not be 2 in the same string next time right?
Link to comment
Share on other sites

  • 1 year later...

Hey guys,

Just been screwing around with querying Source servers myself, Frash's query string set me on the right path for doing it - thanks man.

I know it's a few years late, but here's how you can work around the null characters in the string:

$data = UDPRecv($socket, 1024)
$dataarray = StringSplit($data, Chr(0))

If $data <> "" Then
    $reply_servername = StringMid($dataarray[1],7)
    $reply_map = $dataarray[2]
    $reply_game = $dataarray[4]
    $reply_players = Asc(StringMid($dataarray[6],1,1))
    $reply_maxplayers = Asc(StringMid($dataarray[6],2,1))
Else
    'no response from server
EndIf

Hope this helps someone. :whistle:

Edited by Joshu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...