mIRC Home    About    Download    Register    News    Help

Print Thread
#226722 13/10/10 03:27 AM
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
I dont know about other procotols, but when i received data from web-sites sometimes i receive wrong data frown

Dont know how to detect this bug, but bug exists.

Screenshot: http://img63.imageshack.us/img63/4682/itemmd.png

I using sockread &bvar | echo -s $bvar(&bvar,1-).text and _always_ receive unknowns 8 bytes at the begin of the packet. What it is? Its only from mIRC, I tested it in telnet and all fine.

Update: these bytes are not at the beginning of the package. they simply could be anywhere. frown

Last edited by Voglea; 13/10/10 03:34 AM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
And what mIRC version might this be? If it's 7.1 then you should first try 7.12.

Joined: Dec 2002
Posts: 5,412
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,412
It is really important when posting a script-related bug report that you provide a short test script that reproduces the issue for you. This will allow me, and others, to test your script. Without it, it is not possible to know whether the issue is in your script or whether it is a bug.

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Those 8 mysterious bytes you are receiving, aren't related to mIRC. When connecting to an webpage, and the site doesn't send back a "content-length" header, some webservers send those 8 bytes to tell you how large the next packet is. (\r\nNumber of bytes\r\n)
Telnet, and most webbrowsers know this so they use them but don't display them. smile

try reading with /sockread %var and echoing out %var. You will notice those 8 bytes are on a line by themselves.

I haven't tested it, but I did something similar to get around this problem in one of my script:
Code:
on *:sockread:YOURSOCKET:{
  handle any socket errors that have occured
  if ($sockerr) {
    echo -s SOCKET READ Error: $sockname : $sock($sockname).wsmsg
    return
  }

  ;setup a loop so we will be able to read all data in the rcvdQ
  :loop

  ;read from socket
  sockread &tmp

  ;if no data was read, top processing
  if (!$sockbr) { return }

  ;setup 3 variables to be used as we track down the "packet length"s, and find the first instance of $crlf
  var %a, %b, %x = $bfind(&tmp, 1, $crlf)

  ;loop through finding each instance of crlf
  while ($bfind(&tmp,$calc(%x +1),$crlf)) {
    
    ;set %a to the length between $crlf's found
    %a = $calc($v1 +2 - %x)

    ;if the length between crlf's found is between 5 and 8 bytes, and the data between matches hexidecimal codings
    if (%a isnum 5-8 && $regex($bvar(&tmp,%x,%a).text,/^\r\n[a-f0-9]+$/i)) {

      ;if \r\n0\r\n matches the data between crlfs, then set %b to true, signfying the whole page is read
      if ($bvar(&tmp,%x,%a).text = $crlf $+ 0 $+ $crlf) { %b = $true }

      ;copy the bytes after the 2nd crlf found, to the position of the first crlf(deleting the \r\nBytes\r\n)
      bcopy -c &tmp %x &tmp $calc(%x + %a +2) -1

      ;find the next crlf and set %x to it's position
      %x = $bfind(&tmp,%x,$crlf)
    }

    ;if the data wasn't what we were looking for, set the search location to right after the 2nd found crlf's position
    else { %x = $calc(%a + %x) }
  }

  ;do stuff with &tmp now that all \r\nBYTES\r\n has been removed

  ;if we haven't found the end of the page yet, go back and read again
  if (!%b) { goto loop }

  ;now that that whole page is read, do stuff after reading
}

Last edited by FroggieDaFrog; 13/10/10 12:06 PM.

I am SReject
My Stuff
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A simpler solution than Frog's to remove the extraneous data is to send an HTTP 1.0 request instead of 1.1, which does not support the chunked transfer encoding (which is the reason for the data being broken into chunks with additional length data throughout), thereby forcing the server to send it as a continuous stream of data as you're expecting.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
awesome.
FroggieDaFrog: thanks for the description.
starbucks_mafia: yep. this solves the problem. thanks.

sorry for disturbed :P


Link Copied to Clipboard