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
 
Sockets in TCL

Posted by neo (The Architect), 25 January 2005
I have a problem with sockets now.
Code:
    after $timeOutLimit {set isConnected $timeOutLimit};
    set ftpCtrlSocket [socket -async $McName $PortNo];
    fileevent $ftpCtrlSocket writable {set isConnected 1};

This code works fine when the given port is correct otherwise it gives an error when i try to read from the port after this.

Continued from http://www.wellho.net/cgi-bin/opentalk/YaBB.pl?board=tcl;action=display;num=1106313696

Posted by neo (The Architect), 25 January 2005
I'm beggining to think this socket programming with Tcl is a bad idea.
I thkn using some programming language will be much better.  what do you think?

Posted by admin (Graham Ellis), 25 January 2005
on 01/25/05 at 06:21:39, The Architect wrote:
I'm beggining to think this socket programming with Tcl is a bad idea.
I thkn using some programming language will be much better.  what do you think?


Well ... I advised you to have a look at expect rather than sockets in another thread  

Socket programming does have its uses, but these days low level socket programming is only occasionally the best solution - there are usually better ways of doing things.   There's often little point in writing more code to an existing protocol - better to use code that's out there already, and it's rare to need a new protocol.

Reading your original question, i read "I get an error if the port is not set up correctly".  Err ... yes!! I suggest you check that you get a true value back from the socket command to ensure the socket has correctly opened, and if it hasn't put in an appropriate error handler.   In the majority of live applications, you'll find that over a half the code is involved in error checking and recovery, and only a minority of the code in doing the real work.

Posted by neo (The Architect), 25 January 2005
Cygwin does not have expectk and so that solution is not possible.
BTW when i use the async option how can i be sure the socket command will return a value.
The value being returned now is a valid socket identifier it is onlt when i try a gets or puts that the app crashes.

Posted by neo (The Architect), 25 January 2005
on 01/25/05 at 08:30:13, Graham Ellis wrote:
... and if it hasn't put in an appropriate error handler.   In the majority of live applications...

Does anyone have some example working code of this?


Posted by neo (The Architect), 25 January 2005
I think I can use a 'catch' on the socket command to test if the socket command works in this case then how can I assign the socket descriptor to a variable.
Like this
Code:
if { [catch {socket -async $Addr $Port} errVar} {
  puts stdout "ERROR: $errVar
  return -1;
}

but then how do i save that to a variable if it is a success?

Posted by neo (The Architect), 25 January 2005
Just found out that that works fine if I give an unknown address but when the address is valid and the port is not it proceeds to the next part and crashes.  

And while this is happening the app should not look like its 'hanging'.
How?

Posted by admin (Graham Ellis), 25 January 2005
I'm trying to keep up with the flurry of questions ... we say on here that we aim to post something back within 24 hours and I'm getting to be unsure of which of your own questions you've answered here and which you haven't.  It would be great if you could confirm what's outstanding.

After posting this, I'm only going to have limited net access for the next 24 hours (on a boat, long crossing over the English Channel), so please don't expect too much of a further response for a while.   Free service here - day job must take precedence  

Posted by neo (The Architect), 26 January 2005
No problem  . I understand that I just keep posting whenever i find out something or get an error somewhere. No hurry as such as this is just for my ease of use only thingh i get a bit frustrated when i try so many things and still dont get the app working to my satisfaction.  

Posted by neo (The Architect), 26 January 2005
BTW what i actually want to know is how to createa socket connection to a remote port wiht error checking enabled.
The error may be a invalid address , an invalid port, or any other error.
And as this is an GUII app i also want it not to appear as a 'hung' program while this is happening.

Posted by admin (Graham Ellis), 26 January 2005
Just heading off for my ferry ... saw the further posts ...

Have you come across
    update idletasks
to keep the GUI moving even when you're in the midst of heavy compute?

Posted by neo (The Architect), 26 January 2005
Thanks for the info I will look it up now.
BTW "Bon Voyage"  
I realized that I check the socket with a fileevent command  
Code:
fileevnet $sock w {set connected 1}

does this mean that the socket is readable too?
This works (reading) on a correctly given address but on a wrong address it says an error reading from the socket . How can i trap this error?


Posted by neo (The Architect), 26 January 2005
Hooray !  I've got a manageable solution to the problem at last.  
I just thought I'd let you folks know.
I just do a couple of 'catch'es and at least the app responds after a delay now.


Posted by neo (The Architect), 27 January 2005
I'm writing a kind of telnet GUI interface (to learn Tcl/Tk). I have a slight problem When I click the login button after filling the username and password etc. field my app sort of freezes up.
I get an error when i move the app etc. I guess this is beacuse of the app waiting for me to continue interaction with the connection by providing more info (the next command) etc. Is this right?
If so then should i use the part from the login onwards as a background process?
How do we check up on completion of backgroud processes etc?
Also is this advisable or should i stick to a single thread?



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