Only one application program can be connected with daVinci at a time, but this process is able to visualize many graphs in different windows (see multi-graph mode). If there is a need to have many applications communicating with daVinci in a system architecture, then the application programmer has to provide a single "concentrator process" which is between daVinci and all the applications to synchronize communication.
The disadvantage of this solution is that the application's stdin
and stdout are exclusively reserved for communication with
daVinci.
If more flexibility is needed, e.g. to use other file descriptors than
stdin and stdout, the application has to establish the
pipe communication with daVinci on its own, read
below for details.
Either daVinci connects the Application...
daVinci is able to connect an application program at start-up time
using command-line
option -startappl
or at run-time with menu
File/Connect Application....
By connecting an application, daVinci forks a new UNIX process,
creates two pipes for communication, binds stdin and stdout
of the new process to the end of the pipes and finally starts the specified
application which has to wait for an
initial ok
answer before start sending commands to the API by simply printing them on
stdout. Answers from the API are available for the application by
reading from stdin.
At any time, the user is able to shut-down the currently connected
application by selecting menu
File/Disconnect Application.
But this only works in case of support by the application
(it has to terminate after receiving answer
disconnect).
... or the Application connects daVinci
When the more comfortable connection method (described
above) is not appropriate,
the application program needs to start daVinci on its own.
To do so, the application has to perform the following tasks:
After establishing connection, daVinci sends an initial
ok
answer for synchronization. The application should not start sending commands
to the API before receiving this answer.
daVinci is not able to disconnect the application if it has not
established the connection before. So, menu
File/Disconnect Application
is always deactivated for the connection method described in this paragraph.
Please read the above chapter on UNIX-pipes as well, because some hints that
are not directly related to pipes are relevant for this communication-type
as well.
Communication via TCP/IP sockets
Especially on Windows NT, where pipe communication doesn't work as expected,
another communication mechanism is needed. TCP/IP sockets are much more
flexible, than UNIX pipes. It is even possible to run daVinci and
the application on different machines or different locations in the
network.
Socket server daVinci
For the socket communication, daVinci always acts as the socket
server by listening on a specified port for connection requests of an
application. This can be initiated in two ways, first by setting the
command-line option -server or second
in the
File/Connect Application ...
dialogs. Both ways allow the specification of the socket-port on which
daVinci should listen. It is recommended to use the standard
socket-port reserved exclusively for daVinci for all communications.
daVinci will listen on the specified port until a connection request is received. Than the application will be connected and the listening is stopped, because only one application can be connected to daVinci at a time. After the application has disconnected, listening will start again, if the command-line option -server has been set.
If in the File/Connect Application ...
dialogs a socket-port is specified, that is not equal to the port specified
with -server, daVinci will stop listening on the old port and
immediately starts listening on the new port. After the application has
disconnected, listening will be restarted for the port specified with -server.
The standard socket-port for daVinci
The daVinci project has reserved a standard socket-port for
communications with the daVinci system at the
Internet Assigned Numbers Authority (IANA).
The IANA assigned port number 2542 on September, 3rd 1998 to the
daVinci system.
It is recommended to use this port for all socket communications with the daVinci system, if possible.
In both cases the application is reponsible to connect to daVinci as a socket client and to set up the communication. Because this connection depends on the implementation language of the application, it's impossible to describe it in further detail. A very easy way to connect as a socket-client is available in Tcl/Tk:
socket <hostname> <port>This will connect the application to a socket server on host hostname and port port and delivers a file handle on which commands can be written and answers can be read.
Just try to connect the grapheditor application to daVinci by entering the following commands on command-line:
daVinci -server & grapheditor -client &This will connect the grapheditor application to daVinci as a socket client.
Note: API commands must not have newline or return characters inside. They must have exactly one newline at the end of the command to flush the write buffer. No other characters, even no spaces, must follow this concluding return, except of the next complete command. If these restrictions are not considered, pipe communication with the daVinci API will likely fail.