Opening a Connection

From Apache OpenOffice Wiki
Jump to: navigation, search

The method to import a UNO object using the UnoUrlResolver has drawbacks as described in the previous chapter. The layer below the UnoUrlResolver offers full flexibility in interprocess connection handling.

UNO interprocess bridges are established on the interface, which encapsulates a reliable bidirectional byte stream connection (such as a TCP/IP connection).

  interface XConnection: com::sun::star::uno::XInterface
      long read( [out] sequence < byte > aReadBytes , [in] long nBytesToRead ) 
           raises( com::sun::star::io::IOException ); 
      void write( [in] sequence < byte > aData ) 
           raises( com::sun::star::io::IOException ); 
      void flush( ) raises( com::sun::star::io::IOException ); 
      void close( ) raises( com::sun::star::io::IOException ); 
      string getDescription(); 

There are different mechanisms to establish an interprocess connection. Most of these mechanisms follow a similar pattern. One process listens on a resource and waits for one or more processes to connect to this resource.

This pattern has been abstracted by the services that exports the interface and that exports the interface.

  interface XAcceptor: com::sun::star::uno::XInterface
      XConnection accept( [in] string sConnectionDescription ) 
           raises( AlreadyAcceptingException, 
      void stopAccepting(); 
  interface XConnector: com::sun::star::uno::XInterface
      XConnection connect( [in] string sConnectionDescription ) 
           raises( NoConnectException,ConnectionSetupException ); 

The acceptor service is used in the listening process while the connector service is used in the actively connecting service. The methods accept() and connect() get the connection string as a parameter. This is the connection part of the UNO URL (between uno: and ;urp).

The connection string consists of a connection type followed by a comma separated list of name-value pairs. The following table shows the connection types that are supported by default.

Connection type
socket Reliable TCP/IP socket connection
Parameter Description
host Hostname or IP number of the resource to listen on/connect. May be localhost. In an acceptor string, this may be 0 ('host=0'), which means, that it accepts on all available network interfaces.
port TCP/IP port number to listen on/connect to.
tcpNoDelay Corresponds to the socket option tcpNoDelay. For a UNO connection, this parameter should be set to 1 (this is NOT the default - it must be added explicitly). If the default is used (0), it may come to 200 ms delays at certain call combinations.
pipe A named pipe (uses shared memory). This type of interprocess connection is marginally faster than socket connections and works only if both processes are located on the same machine. It does not work on Java by default, because Java does not support named pipes directly
Parameter Description
name Name of the named pipe. Can only accept one process on name on one machine at a time.

Tip.png You can add more kinds of interprocess connections by implementing connector and acceptor services, and choosing the service name by the scheme<connection-type>, where <connection-type> is the name of the new connection type.

If you implemented the service, use the UnoUrlResolver with the URL uno:mytype,param1=foo;urp;StarOffice.ServiceManager to establish the interprocess connection to the office.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages