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.
Old posts that have not been replied to for several years.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 08, 2004 1:58 am
hey i am trying to understand how to write from a socket to a file i know i am doing something wrong but could someone point me out what it is
yes i know there is a http lib
Code: Select all
#!/usr/bin/tclsh
proc wget {url} {
set host [lindex [split [string trimleft $url "http://"] \x2F] 0]
if {[string match -nocase *:* $host]} {
set port [lindex [split $host \x3A] 1]
} else {
set port 80
}
set path [string trimleft $url "http://$host"]
catch {socket $host $port} sock
if {[string match -nocase sock?? $sock]} {
fconfigure $sock -blocking 0 -buffering line
puts $sock "GET $path HTTP/1.1"
fconfigure $rfile -translation binary
set wfile [open [file tail $url] w]
fconfigure $wfile -translation binary
while {![eof $sock]} {
gets $sock x
if {[string match -nocase {} $x]} {
continue
}
puts $wfile "$x"
}
close $wfile
}
close $sock
}
wget $argv
XplaiN but think of me as stupid
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Sat May 08, 2004 3:31 am
You should have been seeing your problem on stderr (or $errorInfo)...
There is no "rfile" defined... Don't think you even want that line in there at all...
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 08, 2004 11:38 am
huh ur right not sur what that is doing there .. must of been real tired last night .. hehe
but still doesn't work, but it doesn't return any errors to stdout
XplaiN but think of me as stupid
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Sat May 08, 2004 2:01 pm
your string match should probably be "sock*", not "sock??" as the socket descriptor can start at a single digit number and even go past two digits..
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Sat May 08, 2004 6:19 pm
Another thing -- you set the socket to be nonblocking, but then you try to read it in a while loop. Either don't make it nonblocking, or use fileevent to read from it.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sun May 09, 2004 9:15 am
now i am confused of course i am reading from it ..? the transfer of files has worked from server side like this not sur how client side manages it .. so how do you suggest i send data then retreve data ??
XplaiN but think of me as stupid
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Sun May 09, 2004 4:21 pm
I already suggested not making it nonblocking... get rid of the -blocking 0 arg. I'm not sure it will work but at least try it and see what happens.
Also add some debugging statements so you can see what's happening.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Mon May 10, 2004 9:54 pm
i did thing is it doesn't do anything
XplaiN but think of me as stupid
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Tue May 11, 2004 1:03 am
You should have a flush after the puts. Also, you're not sending a valid http request... there should be headers and a blank line after the headers. At the minimum you need another \n. And a flush.