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.
Socket prog. problem

Posted by arunsri (arunsri), 7 April 2006
Hi grp,

I'm using TCL for socket communication.
I have the client prog. running on a Windows host (TCL 8.4) and a server on linux machine (tcl 8.4 again)

My client connects to the server as follows:
#Initiate a client socket and connect to the server
set sock [socket $target $send_port]
puts "host/client: opened socket in host $target server(port) $send_port"

#set socket parameters
fconfigure $sock -buffering line -translation binary
fileevent $sock readable [list talk_2_server $sock]

#Wait and process events on the socket
vwait forever

But the client (running on windows) dosent process any events when the vwait statement is issued. Also I hav checked to make sure that I am doing the proper clean-up in my code  when I am done connecting to the server . i.e.

close $sock
set forever 1

Can you please give pointers as to what might be a problem ? Is it got anything to do with "vwait" on "Windows"? Please help.      

Posted by admin (Graham Ellis), 7 April 2006
Have you tested the server and client separately to establish which / where the problem lies?   Use utilities such as telnet and a daemon such as httpd to try them out one by one with easy protocols

Posted by arunsri (arunsri), 7 April 2006
Right now I am testing if the client can talk to the server after establishing the connection i.e., just send and receive a few lines.

Yes. Telnet does this. But my client prog. jus seem to stall from the vwait statement.

Posted by arunsri (arunsri), 7 April 2006
I also verified with the simple "Echo" server program example (eg. 17_3 and 17_4)  from the "Practical TCL/TK programming" book by Brent B. Welch (4th edition).

No events are processes when I use "vwait event". I tried the client from another linux system too. It complains :

can't wait for variable "event":  would wait forever
   while executing
"vwait event

Now coming to my (project)problem:

I want to be able to transfer a set of data from a windows PC to a linux box using TCL sockets. So I have a client.tcl running on windows and server.tcl on the linux. Upon getting the data the server has to execute a program and return back the output to the host windows pc?

So naturally I have to use vwait in the client to wait for these events to be processed and the exit.

So is there any other work around for this, as "vwait dosent work?"  

Posted by admin (Graham Ellis), 8 April 2006
Can't you simply loop on returned data and exit when you identify the end-of-file or a known sequence that indicates that the remote program has completed?

The program that follows is a complete browser, an I've tested it on Windows ...

set sock [socket 80]
fconfigure $sock -buffering none
puts -nonewline $sock "GET /robots.txt HTTP/1.0\n\n"

while 1 {
    gets $sock line
    if {[eof $sock]} break
    puts $line

In effect, you're using gets to wait for the server!

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