<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/9249" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2005-03-08T19:32:20-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/9249</id>

		<entry>
		<author><name><![CDATA[De Kus]]></name></author>
		<updated>2005-03-08T19:32:20-04:00</updated>

		<published>2005-03-08T19:32:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=47369#p47369</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=47369#p47369"/>
		<title type="html"><![CDATA[check if socket closed by remote]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=47369#p47369"><![CDATA[
if I directly use this, then EOF will be true in the following cases:<br>a) connection to TCP port was refused<br>b) connection to TCP timed out<br>c) connection was closed after it was successfully opend<br><br>I am currently working with this code now:<br><div class="codebox"><p>Code: </p><pre><code>proc getzwstatus {} {global zwstat zwstart zwipif { ${::server-online} &lt; [expr [unixtime] - 120] } {set zwstart [clock clicks -milliseconds]set sock [socket -async $zwip 2593]fconfigure $sock -blocking 0fileevent $sock writable [list getzwstatus:cb $sock]}return 0}proc getzwstatus:cb {sock} {if { [fconfigure $sock -error] == "" } {puts $sock ""flush $sockfileevent $sock readable [list getzwstatus:cb2 $sock]} else {set ::zwstat 0set ::zwping [expr {[clock clicks -milliseconds] - $::zwstart}]}fileevent $sock writable ""return 0}proc getzwstatus:cb2 {sock} {if { [fconfigure $sock -error] == "" } {set trash [read $sock]set ::zwstat 1} else {set ::zwstat 2}fileevent $sock readable ""close $sockset ::zwping [expr {[clock clicks -milliseconds] - $::zwstart}]return 0}</code></pre></div>however, this will create incredible ping results, seems filevent ist really really slow, it seems to trigger once a second so I will get always pings above 1500ms (where I had less than 300ms with blocking I/O). At least the TCL avaible from windrop.sourceforge.net and cygwin compiled eggdrop on winxp.<br><br>When outputting the ping I have an if to ask for ping &gt; 20000 and then print "timeout". this at least gives me the correct TCP status, maybe I have do get the real ping with sync connection after checking asyncronly that the server is avaible (and the bot won't block 20sec for timeout).<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2382">De Kus</a> — Tue Mar 08, 2005 7:32 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2005-03-08T14:50:37-04:00</updated>

		<published>2005-03-08T14:50:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=47363#p47363</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=47363#p47363"/>
		<title type="html"><![CDATA[check if socket closed by remote]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=47363#p47363"><![CDATA[
you check if the connection is closed by using [eof] on fileevent readable channel<br><br>for example, a simple echo server (copied &amp; pasted directly from [fblocked] manpage):<div class="codebox"><p>Code: </p><pre><code># This is called whenever a new client connects to the serverproc connect {chan host port} {    set clientName [format &lt;%s:%d&gt; $host $port]    puts "connection from $clientName"    fconfigure $chan -blocking 0 -buffering line    fileevent $chan readable [list echoLine $chan $clientName]}# This is called whenever either at least one byte of input# data is available, or the channel was closed by the client.proc echoLine {chan clientName} {    gets $chan line    if {[eof $chan]} {        puts "finishing connection from $clientName"        close $chan    } elseif {![fblocked $chan]} {        # Didn't block waiting for end-of-line        puts "$clientName - $line"        puts $chan $line    }}# Create the server socket and enter the event-loop to wait# for incoming connections...socket -server connect 12345vwait forever</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Tue Mar 08, 2005 2:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[De Kus]]></name></author>
		<updated>2005-03-01T10:47:39-04:00</updated>

		<published>2005-03-01T10:47:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=47102#p47102</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=47102#p47102"/>
		<title type="html"><![CDATA[check if socket closed by remote]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=47102#p47102"><![CDATA[
Okay, I made a script which trys to get the real respondtime from a server by connecting, sending an empty line and closing the socket.<br>If I send the server an empty line it will close the socket without notice, so if the server does not close the socket, the process controlling the port is stalled. Can this somehow be indicated? I don't know a "stalled" server to check, so I dont know if my current code would already check it.<br>in my current version I believe EOF would be always true, because the server sends nothing and gets returns always -1 (meaning there is nothing to get).<br>Would it be wise to make a -async connection and a fileevent? but would fileevent trigger if there is only an EOF to read?<br><br>another thing, can I phrase the catch variable output if the connection failed due timeout or due closed port?<br><div class="codebox"><p>Code: </p><pre><code>proc getzwstatus {} {global zwstat zwping zwipset zwstart [clock clicks -milliseconds]if { [catch {set sock [socket $zwip 2593]}] } {set zwstat 0} else {puts $sock ""flush $sockgets $sock trashif { [eof $sock] } {set zwstat 1} else {set zwstat 2}close $sock}set zwping [expr {[clock clicks -milliseconds] - $zwstart}]return 0}</code></pre></div>btw. sorry if it was explained somewhere else, but I couldn't find something that would answer my problem.<br><br>PS:<div class="codebox"><p>Code: </p><pre><code>proc getzwstatus {} {global zwstat zwstart zwipset zwstart [clock clicks -milliseconds]set sock [socket -async $zwip 2593]puts $sock ""flush $sockfileevent $sock readable [list getzwstatus:cb $sock]return 0}proc getzwstatus:cb {sock} {global zwstat zwstart zwpinggets $sock trashset trash2 [fconfigure $sock -error]set zwstat 1close $sockset zwping [expr {[clock clicks -milliseconds] - $zwstart}]putidx 10 "'$trash' '$trash2'"return 0}</code></pre></div>I tried now with fileevent, but no sign that the connections has been closed. Will fileevent only trigger on empty string input, when the socket has been closed? in this case I would only have to check if filevent didnt trigger for so and solong, wouldnt I?<br><blockquote class="uncited"><div>A channel is also considered to be readable if an end of file or error condition is present on the underlying file or device. It is important for script to check for these conditions and handle them appropriately; for example, if there is no special check for end of file, an infinite loop may occur where script reads no data, returns, and is immediately invoked again.</div></blockquote>yeah, but how do I get these errors? how can I check if the function is called, because of an error or because there is data to read? @_o. [fconfigure $sock -error] dosent return errors, if the socket has been closed remotely at least, havent tried yet, what it returns, if the socket connect has been refused.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2382">De Kus</a> — Tue Mar 01, 2005 10:47 am</p><hr />
]]></content>
	</entry>
	</feed>
