Sockets in TCL
Posted by neo (The Architect), 25 January 2005I have a problem with sockets now.
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 2005I'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 2005on 01/25/05 at 06:21:39, The Architect wrote:
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 2005Cygwin 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 2005on 01/25/05 at 08:30:13, Graham Ellis wrote:
Does anyone have some example working code of this?
Posted by neo (The Architect), 25 January 2005I 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.
but then how do i save that to a variable if it is a success?
Posted by neo (The Architect), 25 January 2005Just 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'.
Posted by admin (Graham Ellis), 25 January 2005I'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 2005No 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 2005BTW 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 2005Just heading off for my ferry ... saw the further posts ...
Have you come across
to keep the GUI moving even when you're in the midst of heavy compute?
Posted by neo (The Architect), 26 January 2005Thanks for the info I will look it up now.
BTW "Bon Voyage"
I realized that I check the socket with a fileevent command
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 2005Hooray ! 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 2005I'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?
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho