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 » Tue Apr 13, 2004 6:10 am
I am having a hard time understanding async socket when it infact connects and when not ive seen several examples and read about it but can someone tell me what it is what i am doing wrong .. or give me an working example .. one that shows when u connect and when the connected failed cause i tryed this and it seems to be connecting all the time makes no difference wether it connects or not
tnx in advance
Code: Select all
#!/usr/bin/tclsh
proc open_sock {host port} {
catch {socket -async $host $port} sock
fileevent writable [list check_sock $sock $host $port]
}
proc check_sock {sock host port} {
set error [fconfigure $sock -error]
close $sock
eval report_sock [list $error]
}
proc report_sock {error} {
if {[string match -nocase {} $error]} {
puts "socket connected"
}
}
open_sock [lindex $argv 0] [lindex $argv 1]
Error:
open_sock [lindex $argv 0] [lindex $argv 1]
brain:~# ./sock 127.0.0.1 666
bad event name "check_sock sock3 127.0.0.1 666": must be readable or writable
while executing
"fileevent writable [list check_sock $sock $host $port]"
(procedure "open_sock" line 3)
invoked from within
"open_sock [lindex $argv 0] [lindex $argv 1]
"
(file "./sock" line 20)
socket closes directly before it can check it is writable
listening on [any] 666 ...
connect to [127.0.0.1] from localhost [127.0.0.1] 48096
sent 0, rcvd 0
brain:~#
XplaiN but think of me as stupid
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Wed Apr 14, 2004 12:24 am
Ofloo wrote:
...
cause i tryed this and it seems to be connecting all the time makes no difference wether it connects or not
...
From what you posted, it seems like it does not show it to be connecting all the time... it instead shows an error all the time. You forgot an argument to fileevent, namely the socket.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Wed Apr 14, 2004 5:12 am
<seemed to of posted it twice>
Last edited by
Ofloo on Wed Apr 14, 2004 5:14 am, edited 1 time in total.
XplaiN but think of me as stupid
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Wed Apr 14, 2004 5:13 am
Ok thats something i could of prevented didn't see but i rewrot that like 5 times so it doesn't do anything why is that ?
ive tryed this not once but like 50 times before and i always end up the same the socket connects closes can't check for writable and nothing happens
Code: Select all
#!/usr/bin/tclsh
proc open_sock {host port} {
catch {socket -async $host $port} sock
fileevent $sock writable [list check_sock $sock $host $port]
}
proc check_sock {sock host port} {
set error [fconfigure $sock -error]
close $sock
eval report_sock [list $error]
}
proc report_sock {error} {
if {[string match -nocase {} $error]} {
puts "socket connected"
}
}
open_sock [lindex $argv 0] [lindex $argv 1]
brain:~# ./sock 127.0.0.1 666
brain:~#
listening on [any] 666 ...
connect to [127.0.0.1] from localhost [127.0.0.1] 51639
sent 0, rcvd 0
brain:~#
XplaiN but think of me as stupid
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Wed Apr 14, 2004 9:01 am
You also have to wait for it to connect. Try using vwait or a loop with update.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Wed Apr 14, 2004 12:41 pm
tryed it
when it becomes writable set connect 1
then vwait connect
then if {$connect} {} .. tryed hehe what is it i am doing wrong i know it has to be something .. just can't put my finger on it ..
could maybe someone write a working example ?? doesn't matter how as long as its an async socket that checks if it connects yes or no thats it
XplaiN but think of me as stupid
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Thu Apr 15, 2004 12:06 pm
Code: Select all
proc open_sock {host port} {
if {[catch {socket $host $port} sock]} {
puts "Connection to $host:$port failed: $sock"
} {
fileevent $sock writable [list check_sock $sock $host $port]
vwait ::done
}
}
proc check_sock {sock host port} {
if {[fconfigure $sock -error]==""} {
puts "Connected to $host:$port"
} {
puts "Connection to $host:$port failed: [fconfigure $sock -error]"
}
close $sock
set ::done 1
}
Have you ever read "The Manual"?
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Thu Apr 15, 2004 7:58 pm
seems to be working tnx verry mutch
XplaiN but think of me as stupid