mIRC Homepage
Posted By: bwr30060 trying to learn sockets - 25/01/06 03:01 AM
Hi,

I've decided to try to learn how to use sockets and I have a few ideas for scripts once I learn. I've looked in the help for mIRC and searched these boards to find basic examples of how to use sockets, but I can't get this to work. Basically, for now, I'm just trying to open a socket to www.yahoo.com and see if I can get it to read data to a variable and then write it to a text file so I can see what the info looks like that you get from sockets. I have an alias and two remotes sections to try to do this. Excuse all the "echoes" in the script. I was just testing to see if things were working.
Code:
alias sockettest {
  sockopen yahoo www.yahoo.com 80
  sockread %temp
  echo -a %temp
}
on 1:sockopen:yahoo:{
  echo -a socket opened
  sockread %temp
}
on 1:sockread:yahoo:{
  echo -a hello
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  echo -a %temp
  write yahoo.txt %temp
  goto nextread
  else sockclose yahoo
}
Posted By: RusselB Re: trying to learn sockets - 25/01/06 03:42 AM
I think you have to use a sockwrite command after opening the socket in order to get back information for the sockread event.

If you haven't looked at these, I found 4 tutorials on sockets here

I haven't done much with sockets myself, and most of what I have done was assisted here.
Posted By: bwr30060 Re: trying to learn sockets - 25/01/06 04:37 AM
Thank you very much for that link to the tutorial. I got a basic script working to dump everything from a website to a text file. I even stole some regex code from the tutorial that strips alot of HTML out, lol. I definitely have alot to learn. I decided to try to learn sockets as a challenge. I know there are alot out there, but I might try to write my own weather bot or NFL score bot. Thanks again for your help.
Posted By: bwr30060 Re: trying to learn sockets - 25/01/06 03:39 PM
Hi,

I'm still trying to learn sockets. That tutorial is a big help, but I still can't get it to return what I want. I got it to open a socket to Yahoo and dump everything to a text file, just to start. Eventually, I'd like to have an NFL score bot. For now, since the season is basically over, I'd like to use the scores from the previous weeks of this season. The link to the site for each week is this: http://www.nfl.com/scores/2005/week1

I'd like to eventually have it where I can search for the score for a specific game. I just cant seem to find the scores in the source code. I'm using a piece of regex I found to strip the HTML out, and I'm not sure if that's taking out anything I need. I'm also not totally sure what I'm doing with going to a page that isn't the home page. Thanks.
Posted By: bwr30060 Re: trying to learn sockets - 25/01/06 03:56 PM
I've looked at examples here, and I've got it to dump all the data for the NFL week to a file. I've managed to find the line where it has the score for the game. Now I just need to figure out how to script it to pull the score out. A line for a game score looks like this:
Final1234TTennessee (0-1-0)70007Pittsburgh  (1-0-0)
«71314034

I looked at the real page, and Pittsburgh won that game 34-7, which I found is the right most number in that string of numers after the team record. I'd appreciate any help with this. Thank you.
Posted By: genius_at_work Re: trying to learn sockets - 25/01/06 05:42 PM
If you leave the html codes in, you may be able to use them as position identifiers so that your code can locate the scores you want. Your script doesn't necessarily need the html codes stripped to be able to find something. Try looking at the page without the html stripped and try to locate any common html tags that are around the team names/scores/etc on each page.

-genius_at_work
Posted By: bwr30060 Re: trying to learn sockets - 25/01/06 06:08 PM
Thanks, that's a good idea. Whenever the HTML was stripped, it looked like it was going to be hard to get the scores, because they got turned into a 6 or 7 digit number. I don't know HTML, but it looks like I can find the scores in a line like this:
class=finalscore align=center><b>7</b></td></tr><tr

Thanks again for that help.
Posted By: bwr30060 Re: trying to learn sockets - 25/01/06 08:29 PM
I have this script to start out with to get the info for an NFL bot. The only problem is that the lines are too long for a standard variable. If I understand correctly, a binary variable has no size limit. I tried to read about binary variables, but I can't figure out how to use them. I'd appreciate if someone could tell me how to change the small section of this so that it saves to a binary variable and then writes that to a file. Thanks.
Code:
on 1:sockopen:nfl:{
  echo -a socket opened
  sockwrite -n $sockname GET /scores/2005/week1 HTTP/1.1 $+ $crlf $+ host: nfl.com $+ $crlf $+ $crlf 
  sockwrite -n $sockname Host: nfl.com $+ $crlf $+ $crlf
  sockwrite -n $sockname $crlf
}
on 1:sockread:nfl:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    write nfl.txt %temptext
  }
}
Posted By: FiberOPtics Re: trying to learn sockets - 17/02/06 12:03 PM
Why are you sending the host header twice?
© mIRC Discussion Forums