[TCL] Help with socket -server operations
- From: Andrew Falanga <not_real@xxxxxx>
- Date: Wed, 10 May 2006 11:08:24 -0600
What I'm attempting to accomplish is I have a scenario where I must
write a script that must open a socket and listen for a connection
attempt from an outside program on another host that is performing some
actions on that host for me.
Basically, on host A the TCL script will run and on host B is where a
program is executing that is expecting to contact host A and send status
messages.
Below is a test script I'm using to try and figure this out (I've not
used server type sockets in TCL before now, so am very unfamiliar with
how to make them work). What I have now, doesn't work at all. In fact,
when my fileevent handler is called, I get:
bad event name "sock9": must be readable or writable
So, basically, the script on host A must open a server socket so that
host B can connect, wait for host B to send that it is finished and then
close down the socket (server type) and continue on.
I'm having difficulty figuring out what (file descriptors) should be
placed in blocking/nonblocking mode (if I should change them at all).
Should I turn off buffering? How should I employ vwait? The below
script is where I'm at, at the time I posted this. As I mention, it
does not work. However, I think that you'll have a better time helping
me if you can see my short-comings.
set connection 0
proc HandleStuff { ch caddr cport } {
fconfigure $ch -buffering none
puts "new connection from $caddr"
puts [fconfigure $ch]
if { [fconfigure $ch -blocking] } {
puts "ch is in a blocking state"
fconfigure $ch -blocking 0
}
proc ReadCh { ch } {
gets $ch str
puts $str
if { [regexp {END} $str] } {
set ::connection 1
return
}
}
fileevent readable $ch "ReadCh $ch"
while { 1 } {
after 5000
if 0 {
#vwait $ch
#gets $ch str
if { [regexp {END} $str] } {
puts "fill complete"
puts $str
set ::connection 1
return
}
}
}
}
set serv [socket -server HandleStuff 54321]
vwait $connection
puts "If we got here, it actually worked"
---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.
.
- Follow-Ups:
- Re: [TCL] Help with socket -server operations
- From: Bryan Oakley
- Re: [TCL] Help with socket -server operations
- Prev by Date: Re: Coverity Scan of Open-Source Software
- Next by Date: Re: Coverity Scan of Open-Source Software
- Previous by thread: ANNOUNCE: InstallJammer Multiplatform Installer, version 1.0rc1
- Next by thread: Re: [TCL] Help with socket -server operations
- Index(es):
Relevant Pages
|