mIRC Home    About    Download    Register    News    Help

Print Thread
i wan to use socket to get some info from a site #123141 20/06/05 04:20 PM
Joined: Jun 2005
Posts: 7
A
albert0829 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jun 2005
Posts: 7
i got a site === www.deepsky.ws/top10.asp?c=70
i wan to use socket to get the detail and then use my script to show the info on my channel when ppl ask for the info.... because the info is updated avtime .....
can someone teach me how to do so
thank you

Re: i wan to use socket to get some info from a si #123142 20/06/05 07:09 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:
on *:TEXT:!top10:[color:red]#[/color]: set %chan $chan | sockopen topten www.deepsky.ws 80
on *:sockopen:topten:{ sockwrite -n topten GET http://www.deepsky.ws/top10.asp?c=70 }
on 1:sockread:topten:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  if (HTTP_RESPONSE_TOP10 isin %temp) { msg %chan $remove(%temp,HTTP_RESPONSE_) }
  goto nextread
}

You might want to use the actual channel name instead of just the # (like #mychan) (see in red above)
You can make this sort of thing yourself if you read the help on sockets, I made this with very little modification to the help file example on sockets.

to test manually use an alias like this:
Code:
alias topten { sockopen topten www.deepsky.ws 80 | set %chan $active }

then in the channel window type /topten

Re: i wan to use socket to get some info from a si #123143 20/06/05 07:22 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
It's not a bad idea to close a socket when done as well. /help /sockclose


Invision Support
#Invision on irc.irchighway.net
Re: i wan to use socket to get some info from a si #123144 20/06/05 07:32 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
the web server normally will send a sockclose command when it has finished sending the requested page. However you are correct in that a failed connection will then leave the socket open.
adding a timer into the text event can close the socket if its left open.
Code:
on *:TEXT:!top10:#: set %chan $chan | sockopen topten www.deepsky.ws 80 | .timertopten 1 30 sockclose topten

Re: i wan to use socket to get some info from a si #123145 20/06/05 07:38 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yeah, I mentioned it because I've had some sockets left open and it's annoying to end up setting up a script and have it working, then after you leave, it stops and everyone starts complaining. smile

If a socket isn't closed automatically and you don't have a sockclose in the script itself, it will be left open and the script won't work again until you close it.

I usually include the sockclose in the sockread even, but then again I'm always reading a site that uses HTML tags and has a </html> that lets me know when I can close the socket correctly. I also tend not to use anchors with a goto in my sockread, but that's more personal preference. smile


Invision Support
#Invision on irc.irchighway.net
Re: i wan to use socket to get some info from a si #123146 20/06/05 08:10 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
I copied the sample sockread from the help files, because the webpage is very simple there was no need to do much to it.
Code:
on 1:sockread:[color:red]testing[/color]:{
  if ($sockerr &gt; 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  [color:red]echo 4 %temp[/color]
  goto nextread
}


I only needed to change those red bits to get what the OP asked for.

Re: i wan to use socket to get some info from a si #123147 20/06/05 08:13 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I wasn't saying there was anything wrong with it. I just felt like talking, so I commented on what I tend to do. smile


Invision Support
#Invision on irc.irchighway.net
Re: i wan to use socket to get some info from a si #123148 20/06/05 08:15 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
oh ok laugh