mIRC Home    About    Download    Register    News    Help

Print Thread
#252496 18/04/15 03:29 PM
Joined: Apr 2015
Posts: 18
X
Pikka bird
OP Offline
Pikka bird
X
Joined: Apr 2015
Posts: 18
Hey, I am new to sockets and I have been trying to read up on them but its very confusing. I used a tutorial and ended up with this code, but it does not work. Appreciate the help!
Code:
on *:SOCKOPEN:inv:{
  sockwrite -n $sockname GET /api/invasions
  sockwrite $sockname $crlf
}
on *:SOCKREAD:http: { 
  if ($sockerr > 0) {
    sockread -f %temp  
    if (%temp) {
      var -g %data = %temp
    }
    return 
  }
}

alias z {
  sockopen inv www.toontownrewritten.com 80
  echo -c notify %data
  sockclose inv
}

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
sockets are asyncornous. Meaning they stand outside the falling-rock programma you are most likely used to.

What your current code is doing is opening the socket, echoing %data(which hasn't been set yet), then immediately closing the socket before any events of the socket are fired.

Fixed:
Code:
on *:SOCKOPEN:inv:{
  sockwrite -n $sockname GET /api/invasions HTTP/1.1
  sockwrite -n $sockname Host toontownrewritten.com
  sockwrite $sockname $crlf
}
on *:SOCKREAD:inv: { 
  if (!$sockerr) {
    sockread -f %temp  
    if (%temp) {
      echo -c notify %temp
      ; other processing
    }
  }
}

alias z {
  sockopen inv www.toontownrewritten.com 80
}



---


Since the data you are retrieving is JSON style data, you may want to look at the link in my signature. I wrote a script that makes handling JSON data quite easy from within mIRC

Last edited by FroggieDaFrog; 18/04/15 03:38 PM.

I am SReject
My Stuff
Joined: Apr 2015
Posts: 18
X
Pikka bird
OP Offline
Pikka bird
X
Joined: Apr 2015
Posts: 18
Originally Posted By: FroggieDaFrog
sockets are asyncornous. Meaning they stand outside the falling-rock programma you are most likely used to.

What your current code is doing is opening the socket, echoing %data(which hasn't been set yet), then immediately closing the socket before any events of the socket are fired.

Fixed:
Code:
on *:SOCKOPEN:inv:{
  sockwrite -n $sockname GET /api/invasions HTTP/1.1
  sockwrite -n $sockname Host toontownrewritten.com
  sockwrite $sockname $crlf
}
on *:SOCKREAD:inv: { 
  if (!$sockerr) {
    sockread -f %temp  
    if (%temp) {
      echo -c notify %temp
      ; other processing
    }
  }
}

alias z {
  sockopen inv www.toontownrewritten.com 80
}



---


Since the data you are retrieving is JSON style data, you may want to look at the link in my signature. I wrote a script that makes handling JSON data quite easy from within mIRC


When I used this I get a HTML/1.1 400 Bad Request Message.
Additionally, your program echos out the data, but how would i throw it in a variable to use later?


Link Copied to Clipboard