mIRC Home    About    Download    Register    News    Help

Print Thread
socket problem #247048 19/07/14 11:26 PM
Joined: Jul 2014
Posts: 2
Z
Zen Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Z
Joined: Jul 2014
Posts: 2
Hello,

I'm trying to read the content from this page without any success

http://www.oref.org.il/WarningMessages/alerts.json

this is the script: http://script.quakenet.org/paste/584766

I'm getting the headers but not the content of the page.

Thanks.

Re: socket problem [Re: Zen] #247053 20/07/14 01:50 AM
Joined: Jan 2004
Posts: 1,302
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,302
It's because of the text encoding (UTF-16 Little Endian); I don't know if there's a way to work around this other than sockreading to a binvar.

Re: socket problem [Re: Loki12583] #247059 20/07/14 09:13 AM
Joined: Jul 2014
Posts: 2
Z
Zen Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Z
Joined: Jul 2014
Posts: 2
Originally Posted By: Loki12583
It's because of the text encoding (UTF-16 Little Endian); I don't know if there's a way to work around this other than sockreading to a binvar.


The problem is before the encoding itself i cant read the content that comes after the bracket '{', it seems that there is a char or more that prevents from the socket to read the content...

BTW, i tried with binvar and got the same result...

Re: socket problem [Re: Zen] #247061 20/07/14 12:44 PM
Joined: Jul 2006
Posts: 3,726
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,726
Binary variables will always work, you can't even say you didn't get it to work, or that's because you missed the point of using them.
You should not use $bvar().text to get the text, you can only display $bvar() which will display the ascii value of each byte.

Code:
on *:sockread:oref:{
  if ($sockerr) { return }
  sockread -nf &a
  while ($sockbr) {
    echo -a > $bvar(&a,1-).text :: $bvar(&a,1-)
    sockread -nf &a
  }
}
Using a /while is better than using /goto.
mIRC read the data fine, even if you use a simple %variable, it's just that it can't translate it to produce text, just like with $bvar().text, it just gives $null

Last edited by Wims; 20/07/14 12:47 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: socket problem [Re: Wims] #247063 20/07/14 01:22 PM
Joined: Jan 2004
Posts: 1,302
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,302
If you write/read the binvar to file you can display the content correctly.

Re: socket problem [Re: Loki12583] #247064 20/07/14 01:32 PM
Joined: Jul 2006
Posts: 3,726
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,726
Yeah, but utf16 isn't really supported inside mIRC, probably just the file handling routines handle it.
Maybe a new switch could be added to /sockread when reading into a %variable to handle utf16 correctly.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: socket problem [Re: Zen] #247065 20/07/14 03:27 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Code:
on *:sockread:oref:{
  if ($sockerr) { return }
  if !$sock($sockname).mark {
    var %a | sockread %a 
    if %a == $null { sockmark $sockname 1 }
  }  
  elseif $sock($sockname).mark == 1 {
    sockread &a 
    var %i 1 | while $bvar(&a,%i) != $null {
      var %h %h $base($bvar(&a,$calc(%i + 1)),10,16,2) $+ $base($v1,10,16,2) 
      inc %i 2
    }  
    var %i 1 | while $gettok(%h,%i,32) {
      var %t %t $+ $replace($chr($base($v1,16,10)),$chr(32),space)
      inc %i
    }
    echo -ag $replace(%t,space,$chr(32))
  }
}