Code: Select all
proc racInfo {} {
Code: Select all
proc racInfo { } {
Code: Select all
proc racInfo {} {
Code: Select all
proc racInfo { } {
Code: Select all
set ::RacInfo [::http::data $token]
Code: Select all
switch [::http::status $token] {
This may depend entirely on the version of http package sourced into the script, or defaulted by install or what have you. This could also be related to the state after peculiarity, and not really be an error at all but a bug within http package itself.nml375 wrote:Oh, and by the way...
If the switch is the error, how come we get our custom log output saying the request failed due to a timeout? (atleast I do in my tests) :p
Code: Select all
set socket [socket -async 127.0.0.1 80]
fconfigure $socket -blocking off
Code: Select all
fileevent $socket writable [list socketConnected $socket]
Code: Select all
proc socketConnected {socket} {
putlog "connected: $socket"
fileevent $socket writable [list doRequest $socket]
}
Code: Select all
proc doRequest {socket} {
if {[llength $::theData] > 0} {
puts $socket [lindex $::theData 0]
set ::theData [lrange $::theData 1 end]
} {
fileevent $socket writable ""
fileevent $socket readable [list getResponse $socket]
flush $socket
}
}
Code: Select all
set theData [split "GET /x/playlist.cgi HTTP/1.0
Host: somehost:someport
" \n]
Code: Select all
proc getResponse {socket} {
gets $socket line
if {[eof $socket]} {
putlog "Connection closed."
close $socket
} elseif {![fblocked $socket]} {
append ::RacInfo "$line\n"
}
}
Code: Select all
#Start with the procs...
proc socketConnected {socket} {
putlog "connected: $socket"
fileevent $socket writable [list doRequest $socket]
}
proc doRequest {socket} {
if {[llength $::theData] > 0} {
puts $socket [lindex $::theData 0]
set ::theData [lrange $::theData 1 end]
} {
fileevent $socket writable ""
fileevent $socket readable [list getResponse $socket]
flush $socket
}
}
proc getResponse {socket} {
gets $socket line
if {[eof $socket]} {
putlog "Connection closed."
close $socket
} elseif {![fblocked $socket]} {
append ::RacInfo "$line\n"
}
}
#Prepare our query and clear RacInfo:
set RacInfo ""
set theData [split "GET /x/playlist.cgi HTTP/1.0
Host: ${RacIP}:${RacPort}
" "\n"]
#Lets fire up the socket and start the request:
set socket [socket -async $RacIP $RacPort]
fconfigure $socket -blocking off
fileevent $socket writable [list socketConnected $socket]
Code: Select all
proc RacSkt {} {
global RacIP RacPort
if {[catch {set RacSock [socket -async $RacIP $RacPort]; fconfigure $RacSock -blocking 0;}]} {
putlog {Socket NOT Detected};
return 0;
} else {
putlog {Socket Detected};
fileevent $RacSock writable [list RacNfo $RacSock];
}
}
proc RacNfo {RacSock} {
global RacInfo RacIP RacPort
flush $RacSock;
puts $RacSock "GET /x/playing.cgi HTTP/1.0";
puts $RacSock "User-Agent: Mozilla";
puts $RacSock "HOST $RacIP:$RacPort";
puts $RacSock "";
flush $RacSock;
putlog {Puts to Socket: COMPLETE!};
set T 0;
while {($T <= 1000)&&(![eof $RacSock])} {
incr T;
set RacInfo [gets $RacSock];
}
putlog {Gets From Socket: COMPLETE};
flush $RacSock;
close $RacSock;
putlog {Connection Close and Complete}
}