mIRC Home    About    Download    Register    News    Help

Print Thread
#255348 11/10/15 07:19 PM
Joined: May 2015
Posts: 133
K
Vogon poet
OP Offline
Vogon poet
K
Joined: May 2015
Posts: 133
Driving myself crazy with this one, i believe i understand how sockets work, albeit a very basic level.

I'm trying to read data from a site: http://apis.rtainc.co/twitchbot/following.php?channel=randomchannel&user=randomuser

I have the following code

Code:
alias followed {
  sockclose followed
  sockopen followed apis.rtainc.co 80
}

on *:SOCKOPEN:followed:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -nt $sockname GET /twitchbot/following.php?channel=randomviewer&user=randomuser HTTP/1.1
  sockwrite -n $sockname Host: apis.rtainc.co
  sockwrite $sockname $crlf
}

on *:SOCKREAD:followed:{
  if ($sockerr) { sockclose $sockname }
  var %data
  sockread %data
  echo %data
}


I should be echoing: randomuser is not following but i am only echoing raw headers.

Any thoughts? I'm using similar socket scripts already and can read data from a website just fine.

Thanks!


twitter @keyeslol
keyeslol #255350 11/10/15 07:33 PM
Joined: Feb 2015
Posts: 243
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Feb 2015
Posts: 243
Try adding this after the sockread %data
Code:
    
while ($sockbr) {
      sockread %data
    }

and this event
Code:
on *:sockclose:followed: {
    var %data
    sockread -f %data
echo -a %data
}

And check if it echoes the line you want smile

OrFeAsGr #255351 11/10/15 07:40 PM
Joined: May 2015
Posts: 133
K
Vogon poet
OP Offline
Vogon poet
K
Joined: May 2015
Posts: 133
So that seemed to work, however it echo's only when the socket closes. The question is, can i move it to the sockread or force the socket to close faster?


twitter @keyeslol
keyeslol #255352 11/10/15 07:49 PM
Joined: Feb 2015
Posts: 243
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Feb 2015
Posts: 243
i found it! add this on the sockopen event
Code:
sockwrite -nt $sockname Connection: Close

smile

OrFeAsGr #255353 11/10/15 08:22 PM
Joined: May 2015
Posts: 133
K
Vogon poet
OP Offline
Vogon poet
K
Joined: May 2015
Posts: 133
You helped me get to what i wanted. The socket close wasn't functioning exactly as i wanted it to.

I had to write some additional code to get it working but you helped me go in the right direction!


twitter @keyeslol

Link Copied to Clipboard