|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
Grabbing a Web Page with Socket
New to tcl, but I wanted to try grabbing a web page with socket. In this case, it's Google's about page, and I'm trying to read it into a variable called test. Unfortunately, the script seems to never do anything! What am I doing wrong? code ------- set sockChan [socket "www.google.com" 80] puts $sockChan "GET /intl/en/about.html HTTP/1.0\n\n" gets $sockChan test close $sockChan ------- Also, is it important that www.google.com be in quotes? Thanks! - GeekUnit
On May 27, 4:31 pm, GeekUnit <mrn@gmail.com> wrote: > New to tcl, but I wanted to try grabbing a web page with socket. In > this case, it's Google's about page, and I'm trying to read it into a > variable called test. Unfortunately, the script seems to never do > anything! What am I doing wrong? > set sockChan [socket "www.google.com" 80] > puts $sockChan "GET /intl/en/about.html HTTP/1.0\n\n"
You just need to flush the output. Some channels in Tcl are created by default in block-buffered mode, sockets are in the group. Just insert "flush $sockChan" after the [puts], (or change the buffering mode with [fconfigure]), and your code will work. That said, while putting your hands in the grease is an unbeatable way of learning, for the specific task for http clientside in pure Tcl, check out the already-written package http (it is in most distribs of Tcl). -Alex |
 |
 |
 |
 |
|