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.

Problem with "puts" to sock

Old posts that have not been replied to for several years.
Locked
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Problem with "puts" to sock

Post by Kripton »

I got my EggDrop running as WebServer! The problem is, the Bot doesn't send the hole text, it stops after approx. 20 lines! The Script (just the sock-send-part):
fconfigure $sock -translation binary -buffersize 1000000 -blocking 0
set filechan [open $servfile r]
while {![eof $filechan]} {
gets $filechan html
puts $sock $html
flush $sock
}
close $filechan
What I found out: It can read the whole textfile. It must be the output to the socket! I was reading about "blocking", "nonblocking", "vwait" and "Tcl_DoOneEvent"! Of course all my tests with this failed and I got even more confused about it!

The Delay-Command (tcl_sleep) didn't work as well!

How can I solve this problem?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

First, you don't need to flush the socket every time through the loop. Once after the loop would be fine. Second, why such a big buffersize? Puts will increase the buffer as it needs it, so you shouldn't need to set such a big one initially. Third, the problem could easily be somewhere else. Where do you close the socket? Do you send the correct http response and headers?

If you want to send the whole file, why don't you try something like:

set fp [open $file r]
set html [read $fp]
close $fp
puts -nonewline $sock $html
close $sock

If you want to transfer very large files (megabytes) then the fcopy command is better.. or at least sending it one part at a time, with fileevent.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Code: Select all

fconfigure $sock -blocking 0 -buffering line 
or try this instead of flushing each time worked for me so far .. just put that first then gets line and puts line
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

http://cvs.ofloo.net/httpadm/

take a look at this it is a webserver i am writing with http admin still workin on the admin part but the webserver is functional ..
XplaiN but think of me as stupid
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Post by Kripton »

Ok, it works now! Yes, the error was within the HTTP-Headers!
I think I just paste the URL to my script here (Yes, it works :P ), because I think it might be helpful to some purposes! The special thing is, you can script your WebPages (In a way like PHP). A little example:

Code: Select all

 <egg> set output "[llength [chanlist #chan]]" </egg> 
in your html-file whould return the number of peeps in a chan on the viewers WebBrowser! This is better than creating WebPages with your EggDrop and hosting them with another WebServer because they are really updated in realtime and you can execute every code you want on your eggdrop!
I named it EWIO (Eggdrop Webserver with Interactive Output)
Might be good or just [censored] :P

http://82.165.25.75/~kripton/ewio.tcl

NOTE: This Script is not 100% made by me, but I don't know where I got the WebServer-Part from! SORRY
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

yep same with the script above i posted ;) i am still working on the http admin interface tho the webserver is function nal and supports gif jpg .. and so on maybe suggestion for ur next version ;)
XplaiN but think of me as stupid
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Post by Kripton »

Yes, ok! GIFs work mostly, JPEGs don't! I will work on the binary-support! But for sending commands to the eggdrop, its yet enough! Maybe, if I have more time!
Locked