Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Closing clients?

Posted by neilvp (neilvp), 18 March 2005
Oh Great Guru Graham, your assistance please..

The script below successfully works first time around,  I get the expected response and the program terminates.
If, however, I run the program again the program hangs at the 'trying to talk to..'
So my main question is, do I have to close the socket before ending the program and if so what would be the correct way of doing so?
If I do not have to close the socket what is happening to cause the problem and what can I do about it?

Other questions are :-
a) is there an appropriate three finger salute to terminate a hung program so that I do not have to close the tclshell down each time the program hangs?
(I know I should use Expect and will in future, honest) and
b) how do I get the tclshell to display the directory I am in please.
Many thanks


# *******************************
# ** TCL Test Suite For **
# **
# ** 18 Mar 2005
# **
# ** N Peers
# **
# *******************************

# This does use Expect
package require Expect

# IP Address of the test NEMI is

set nemiaddress
set portaddress 52729

# Limit the time out to 2 seconds

set timeout 2

# turn off screen echo
log_user 0

# set up an array of lan types

set lantype(2c) "Protected Fibre Channel ER"
set lantype(06) Gigabit

# First Off make sure we are talking to the NEMI

spawn ping $nemiaddress
puts "ping started"
expect \
     timeout      { puts "No reply - NEMI @ $nemiaddress not found"
                   puts "Correct ip address?"  
     eof      { puts "End of file"  }
     "Reply from $nemiaddress" { puts "NEMI found @ $nemiaddress" }

# OK lets see if I can talk to this thing

puts "Trying to talk to $nemiaddress $portaddress"

set sock [socket $nemiaddress $portaddress]
puts $sock "L0 0A 1\n"
flush $sock

set reply  [set reply [gets $sock]]
puts $reply

puts "End of Script"

Posted by admin (Graham Ellis), 19 March 2005
b) The built in pwd command returns the current directory

main question)  I would, yes, suggest you close your connection before exiting. It sounds like it's important to close the remote socket by sending an approrpiate termination / going away message ... and remember to flush the socket when you do that;  with socket programming the correct fconfigures and flushes are important to avoid freezes and "won't work next time" problems.

Interesting thing with socket connections ... I can take my laptop, unlplug it from the network, plug it in again to (example) another port on the hub and maintain my socket connection.  Leads me to conclude that the network software isn't sensing a departing client ... which leads to the conclusion that you're going to have to send that "I'm gone" the first time in order to leave the door open the second time you arrive.

a) Does ^C work for you??

Please excuse the slight "rush" this morning ... off here, there, everywhere this weekend!   Back for work on Monday though.

Posted by neilvp (neilvp), 21 March 2005
Hi Graham
Thanks for the prompt repsonse.

Using an explicit close command (i.e. close $sock) seems to have fixed the problem.
This though does raise another question though as I was under the impression that when a script terminated it closed everything anyway. - Was I mistaken in that or have I found a feature of TCL under Windows XP?

Ctrl-C does not recover a hung program ... any other suggestions?

What I meant to ask, regarding the display of the directory was - how do I get the command prompt within a tcl shell to display the pwd?
e.g. c:\tcl\programs%

And ... if anyone else reads this, Expect from ActiveState does not work under Windows 98. (They do not claim it does and, yes, I should have RTM before installing the code.)

Posted by neo (The Architect), 2 April 2005
on 03/21/05 at 14:35:57, neilvp wrote:
And ... if anyone else reads this, Expect from ActiveState does not work under Windows 98. (They do not claim it does and, yes, I should have RTM before installing the code.)

What about using CYGWIN?

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho