mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2005
Posts: 74
D
defiant Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Mar 2005
Posts: 74
Hi, im having a problem reading a .xml page thru a socket... if anyone could help me?

Code:
 
alias ds.getinfo {
  sockopen servers daoc.goa.com 80
}

on *:sockopen:servers:{
  sockwrite -n servers GET /herald/nb_connected2.xml HTTP/1.1
  sockwrite -n servers Host: daoc.goa.com
  sockwrite -n servers $crlf
}

on *:sockread:servers:{
  sockread %vrs
  echo -a %vrs
}
 


Now if i replaced
Quote:
sockwrite -n servers GET /herald/nb_connected2.xml HTTP/1.1
by
Quote:
sockwrite -n servers GET /herald/servers.xml HTTP/1.1


then it can read.. Anyone know how to get it working?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
herald/nb_connected2.xml HTTP/1.1

comes back with
Code:
HTTP/1.1 200 OK
Age: 0
Date: Fri, 25 Mar 2005 22:47:03 GMT
Content-Length: 959
Content-Type: text/xml
Server: Apache
Last-Modified: Fri, 25 Mar 2005 22:47:02 GMT
ETag: "30800c-3bf-424494e6"
Via: 1.1 nc2 (NetCache NetApp/5.6R1)

<?xml version="1.0" encoding="UTF-8" ?><server_status poptot="14399" updated="25-03-2005 23:47:00"><lng val="English" poplng="2283"><server name="Excalibur" type="Normal" pop="1178" status="Up"/><server name="Prydwen" type="Normal" pop="595" status="Up"/><server name="Camlann" type="PvP" pop="510" status="Up"/></lng><lng val="French" poplng="4272"><server name="Broceliande" type="Normal" pop="1369" status="Up"/><server name="Ys" type="Normal" pop="1290" status="Up"/><server name="Orcanie" type="Normal" pop="1041" status="Up"/><server name="Carnac" type="Normal" pop="572" status="Up"/></lng><lng val="German" poplng="7844"><server name="Avalon" type="Normal" pop="1894" status="Up"/><server name="Stonehenge" type="Normal" pop="1699" status="Up"/><server name="Lyonesse" type="Normal" pop="1614" status="Up"/><server name="Dartmoor" type="Normal" pop="1322" status="Up"/><server name="Logres" type="Normal" pop="1315" status="Up"/></lng></server_status>


The last line is 960 bytes and cant be loaded into a mirc string 930 (aprox) limit, you well have to switch to &binvar variables and disect the line manually, unless your just downloading it to file anyway, in which case just switch to binvar after the first $null returned %vrs and dump to a file.

some example code (dont know if u needed it)

Code:
on *:sockread:servers:{
  var %vrs
  if (%servers.header) {
    sockread %vrs
    if (!%vrs) { set -s %servers.header $false | var %vrs = --- header ends --- }
    echo -a %vrs
  }
  ;
  ; * yes the reverse IF condition below is on purpose instead of a using a ELSE
  ;
  if (!%servers.header) {
    sockread -fn &binvar
    var %i = 1
    while (%i <= $sockbr) {
      echo -a $bvar(&binvar,%i,512).text
      inc %i 512
    }
  }
}


On using this you sometimes get strange results becuase
When using sockread -f %vrs it says it reads to a $crlf terminated line or the end of buffer, in fact it reads to a $lf terminated line also (might do $cr as well never checked tho)
But when using sockread -fn &binvar it says it reads to a $crlf terminated line or the end of buffer, and it really does, a $lf (maybe also $cr) are included in the &binvar
This being the case, if you are parsing out the lines you need to know that you may infact have more than one line in the &binvar.

Joined: Mar 2005
Posts: 74
D
defiant Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Mar 2005
Posts: 74
Ah thanks, so it's readable :P

I was just wondering, the stuff shoud indeed be written to a file (txt). You said 'dumb' the text to a file.. how exactly? smile

Thanks alot

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
You said 'dumb' the text to a file.. how exactly? smile

I said "dump", but here it is...

Code:
alias ds.getinfo {
  sockopen servers daoc.goa.com 80
}
;
on *:sockopen:servers:{
  sockwrite -n servers GET /herald/nb_connected2.xml HTTP/1.1
  sockwrite -n servers Host: daoc.goa.com
  sockwrite -n servers $crlf
  set %servers.header $true
  write -c filename.txt
}
;
on *:sockread:servers:{
  var %vrs
  if (%servers.header) {
    sockread %vrs
    if (!%vrs) { set -s %servers.header $false | var %vrs = --- header ends --- }
    echo -a %vrs
  }
  ;
  ; * yes the reverse IF condition below is on purpose instead of a using a ELSE
  ;
  if (!%servers.header) {
    sockread &binvar
    bwrite filename.txt -1 -1 &binvar
    ;^ I deleted the file before hand using "write -c" as this bwrite appends to it.
  }
}
;
;* use below instead if you just want to save the whole thing including the header.
;
on *:sockread:servers:{
  sockread &binvar
  bwrite filename.txt -1 -1 &binvar
  ;^ I deleted the file before hand using "write -c" as this bwrite appends to it.
}


Link Copied to Clipboard