winsend - send implementation for windows platform
|
The winsend package is an attempt to provide the complete functionality of the Tk send command using the Microsoft Windows platform. The two key points are inter-process communications between one interpreter and another, and automatic registration of interpreters with a central source. With the Tk send command this is done via the X Windows server. The winfo interps command returns a list of registered interpreters and the send command allows you to execute Tcl commands in the named interpreter. Finally tk appname allows the programmer to select the registration name.
There are alternative methods for providing remote command xecution on the windows platform. The comm package that is now part of tcllib provides cross-platform remote command execution by the use of TCP sockets. The disadvantage of this package is the lack of interpreter registration. Potential clients need to be told of the port number to use to communicate with the server application.
The other method is the dde package which is supplied as part of the Tcl core. This provides automatic registration and the available interpreters can be listed by excuting dde servers TclEval {}. The disadvantage if the DDE system is that a badly written windows application can hang your application. DDE uses windows messages to do its work. If an application isn't processing it's message queue then the dde command given above will never complete.
An alternative is available using Microsoft's COM technology. COM is designed to permit interprocess communication through the use of interfaces. There is also a system provided registration object where a reference to a running interpreter can be lodged. Querying the list of available servers only communicates with the Running Object Table (the ROT) and doesn't need to send messages to any applications. Sending commands does require the server interpreter to be processing events - but if the server is not processing these events then the command will time out. This is a significant advantage over DDE. Also, because we are using standard OLE automation interfaces it becomes possible for any other Automation capable application to send commands to Tcl for execution. Such applications include Microsoft Office applications, Internet Explorer and many others. For instance the following VB script can be run using the Windows Scripting Host cscript application using cscript test.vbs
Set interp = GetObject("\\.\TclInterp\tkcon.tcl") interp.Send "puts {Hello from VB Script}" WScript.Echo interp.Send("info tcl") |
% package require winsend 0.6 % winsend appname MyApp MyApp % winsend send MyApp info tcl 8.3 |
An example session between two interpreters
An example (from tkcon): from a concurrent tclsh: % package require winsend | % package require winsend 0.6 | 0.6 % winsend interps | % winsend interps tkcon.tcl | tkcon.tcl TCLSH.EXE | % winsend send tkcon.tcl set x 1 | 1 % set x | 1 | % winsend send TCLSH.EXE set y 2 | % after 2000 {set zx 1} ; vwait zx 2 | % set y | 2 | % exit % winsend interps | tkcon.tcl | |
Documentation is located at http://tclsoap.sourceforge.net/winsend.html