Reputation: 717
I am trying to build a socket in TCL using the socket -server accept <port>
command and then using the vwait forever
loop - The simplest possible socket.
I am able to connect to the server fine but my issue is -- How do I close the socket when it is no longer needed without having to exit the application.
Some context on my application:
It is a Synopsys tool with a TCL shell.
I am planning on building a GUI using TK and ideally, I would like to develop it in Python for scalability reasons (plus the TK interface through Synopsys TCL shell is not the regular TCL/TK interface).
When the forever
event loop is running, the shell is constantly listening - Making the application's own TCL user prompt unavailable - I am not expecting that the shell will be available when some command over the socket is running, but I do expect the shell to be available once the command over the socket is completed. (I understand that this will be a little complex to implement....but just putting the question out)
When I try using the exit
command passed through the socket, the application (the entire one) is closed.
Is there any command that I can pass over the socket to close the socket only and not close the entire application?
Please let me know if more details are needed.
Upvotes: 0
Views: 698
Reputation: 33193
A call to exit
will exit the interpreter and cause the process to close. You close sockets by using the close
function on the channel. In a server application with a connected client there are two sockets. Once you have dealt with all transactions from the client your server code should call close
on the client socket. This was provided to your code in the callback function you passed in when creating the server socket. The server socket also needs to be closed at some point. How you do that depends on your application and platform. On a unix system you might use an extension to trap a signal to call this close function. Or you might close the server in response to some input from a control socket or standard input channel. The interpreter will not be reading and parsing input unless you add code to do this. Using fileevent
you can arrange to read from multiple channels and using info complete
you can read from stdin and evaluate the input to get a REPL loop going for your server. An implementation of this can be found online and I imagine the wiki has some examples as well.
Upvotes: 0