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.

host unavaible on webpage error

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

host unavaible on webpage error

Post by droolin »

I wrote an eggy script for our shoutcast radio channel. Part of what this script does is check the status web page every time someone joins the channel to determine if someone is streaming or not.(Bloody dj's don't know how to follow instructions). There are times when the bot can't reach the host(shoutcast is on the same server/shell), which probably occurs because nobody is streaming and shoutcast server is just not responding(don't know if this is the case).

The problem I'm having is that when I receive that error:
[21:13] Tcl error [ListenersCommand]: couldn't open socket: host is unreachable
That the rest of the commands do not run... And it seems, that after it receives that error that even if someone is streaming... The bot can not connect to the host.

So, my question is 2 fold.
1). How do I check for errors on the read to the web page and make the rest of the code in the paragraph work.
2). Why doesn't it connect to the web page after I know that it is responding. And yes, it will connect ok to the web page most of the time.

Code: Select all

 foreach lcl_URL_Port_type $gbl_ary_check_web_pages      {
                set lcl_URL_fields [split $lcl_URL_Port_type ":"]
                set lcl_URL  [lindex $lcl_URL_fields 0]
                set lcl_Port [lindex [split [lindex $lcl_URL_fields 1] "~"] 0]
                set lcl_StreamWebPageScoket [socket $lcl_URL $lcl_Port]
                # I have no idea what this [censored] does. Not a clue
                puts -nonewline $lcl_StreamWebPageScoket "GET /7.html HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-sh
ockwave-flash, */*\nAccept-Language: en-us\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; T312461; (R1 1.3); .NE
T CLR 1.0.3705; .NET CLR 1.1.4322)\nHost: www.awesomechat.net\nConnection: Keep-Alive\n\n"

                flush $lcl_StreamWebPageScoket
                while {![eof $lcl_StreamWebPageScoket]} {set line [gets $lcl_StreamWebPageScoket]
                        set lcl_crap "body"
                        set lcl_Start 0
                        set lcl_End   0
                        if { [string match *$lcl_crap* $line] } {
Please note, that this is a common procedure that is called from a number of other procedures. And that two web pages are pulled... 2 different ports due to 2 instances of shoutcast running.

droolin[/code]
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

actualy, now that I posted that.

Post by droolin »

I see something wrong with it...

But that still doesn't answer one of my questions... I should always check to make sure that a command executes properly such as accessing a web page, accessing a file.

How do you go about doing that so that the rest of the procedure still executes and you do not receive tcl errors?

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

Post by rosc2112 »

# I have no idea what this [censored] does. Not a clue


Uhm... Thats one way of grabbing webpages. Using the http package is prefered nowdays. You can use catch[] to handle error conditions, for example:

Code: Select all

catch {set page [::http::geturl $movieurl -timeout $::movietimeout]} error
	if {[string match -nocase "*couldn't open socket*" $error]} {
		puthelp "PRIVMSG $chan :Error: couldn't connect to filmspot.com..Try again later."
		return
	}
	if { [::http::status $page] == "timeout" } {
		puthelp "PRIVMSG $chan :Error: Connection to filmspot.com timed out..Try again later."
		return
	}
	set html [::http::data $page]
	::http::cleanup $page
	if {[regexp $regexm $html match moviedata]} {
Thats an example of retrieving web data and handling the error conditions, using the http package.
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

Thank you

Post by droolin »

Sorry about not removing that comment before I posted...

But I do appriceate the information both on the catch and on the http package. Especially the examples.

droolin
Post Reply