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
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho