This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Egghttp, sockets in sockets..

Help for those learning Tcl or writing their own scripts.
Post Reply
l
leandro
Voice
Posts: 13
Joined: Sat Jun 02, 2007 9:43 am

Egghttp, sockets in sockets..

Post by leandro »

I am creating an online database, So I need to connect to a webpage, read the first line, open another connection, fill in some data, and then go to the second, and so on.


Now, I have this:

Code: Select all

et url "http://localhost/akicks/todo.php"
set trigger "!test"


if {![info exists egghttp(version)]} {
  putlog "egghttp.tcl was NOT successfully loaded."
  putlog "http-akicks.tcl has not been loaded as a result."
} else {
  proc your_callbackproc {sock} {
    global url
    set headers [egghttp:headers $sock]
    set body [egghttp:data $sock]
    foreach line [split $body \n] {
    regsub -all -nocase {<br>} $line "" line
    regsub -all -nocase {<b>} $line "" line
    regsub -all -nocase {</b>} $line "" line
    set id [lindex $line 0]
    set secondline [string trimleft $line $id]
    set com [lindex $secondline 0]
    set newurl "http://localhost/akicks/mark.php?id=$id&com=$com&pass=12ledro"
    set sockset [egghttp:geturl $newurl akick_proc]
    return 1

}
proc akick_proc {sock} {
    set headersset [egghttp:headers $sockset]
    set bodyset [egghttp:data $sockset]
    foreach line [split $body \n]
    if {$bodyset == "Ok"} {
      putlog "success"
    }
}
}

  bind dcc o|o $trigger our:dcctrigger
  bind pub o|o $trigger our:pubtrigger
  proc our:dcctrigger {hand idx text} {
    global url 
    set sock [egghttp:geturl $url your_callbackproc]
    return 1
  }  
  proc our:pubtrigger {nick host hand chan arg} {
    global url 
    set sock [egghttp:geturl $url your_callbackproc]
    return 1
  } 
  putlog "http-akicks.tcl has been successfully loaded."
}



But this only seems to work for the first line. Any suggestions?
l
leandro
Voice
Posts: 13
Joined: Sat Jun 02, 2007 9:43 am

Post by leandro »

Anyone? Pleaseee?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Switch to the http module that comes with tcl and I might be able to help.
l
leandro
Voice
Posts: 13
Joined: Sat Jun 02, 2007 9:43 am

Post by leandro »

Im afraid I dont know about any HTTP module... Do you have a tutorial somewhere?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Search the forum for examples.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

The http package is well documented in the tcl man pages.. There's also a thousand example scripts here and in the archives (all of my webscripts use the http package, a few use the socket code, none use egghttp.tcl)
Post Reply