[TCL] Help with socket -server operations



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.
.



Relevant Pages

  • Re: SOCKET_ERROR [10054]
    ... using SocketWrench .net component. ... connection was forcibly closed by the remote host. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
    ... stream_socket_server simply listens, stream_socket_accept handles the connection, stream_set_write_buffer and stream_set_blocking help you keep up, especially when combined with stream_get_line, no need to shile forever when you can just: ... Key I find though is multithreading, listener thread with stream_socket_server, 2 or 3 stream_socket_accept threads and a pair of new thread spawned to handle each connection. ... "If you want a high speed socket server, use the low-level sockets instead. ... And it stays high until I stop the script and restart it. ...
    (php.general)
  • confusion and problems with first socket script
    ... i am getting some problems with my first socket ... the server script suppose to accept one ... the client script is working fine. ... Closing Connection: ...
    (comp.lang.python)
  • Re: -timeout for "socket"
    ... Host won't respond, and it seems, that "socket" has very long timeout set ... puts "Connection failed: $err" ...
    (comp.lang.tcl)
  • Socket Setup and program in C- help
    ... Server (Host) platform is HP-UX 10.2. ... Would like to set up connection to that from the HOST server to be ... socket to port*/ ...
    (comp.unix.programmer)