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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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 ...

Code:
set sock [socket 64.62.240.12 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 www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho