打开连接
From Apache OpenOffice Wiki
< Zh | Documentation
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
如前面章节所述,使用 UnoUrlResolver 导入 UNO 对象这一方法有一些不足之处。
UnoUrlResolver 的下一层为处理进程间连接提供了非常大的灵活性。
UNO 进程间桥建立在 com.sun.star.connection.XConnection 接口上,此接口封装一个可靠的双向字节流连接(如 TCP/IP 连接)。
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();
};
建立进程间连接有多种不同的机制。其中多数机制遵循类似的模式。一个进程对资源进行侦听,并等待一个或多个进程连接到此资源。
此模式是通过导出 com.sun.star.connection.Acceptor 接口的 com.sun.star.connection.XAcceptor 和导出 com.sun.star.connection.Connector 接口的 com.sun.star.connection.XConnector 服务抽出概念。
interface XAcceptor: com::sun::star::uno::XInterface
{
XConnection accept( [in] string sConnectionDescription )
raises( AlreadyAcceptingException,
ConnectionSetupException,
com::sun::star::lang::IllegalArgumentException);
void stopAccepting();
};
interface XConnector: com::sun::star::uno::XInterface
{
XConnection connect( [in] string sConnectionDescription )
raises( NoConnectException,ConnectionSetupException );
};
侦听进程使用 Acceptor 服务,而主动连接服务使用 Connector 服务。方法 accept() 和 connect() 以参数的方式获取连接字符串。它是 UNO URL 中的连接部分(位于 uno:和 ;urp 之间)。
连接字符串包含一个连接类型,后跟一个逗号分隔的名称值对列表。下表所示为默认情况下支持的连接类型。
| 连接类型 | ||
|---|---|---|
| 套接字 | 可靠的 TCP/IP 套接字连接 | |
| 参数 | 说明 | |
| host | 要侦听/连接资源的主机名或 IP 编号。可以是本地主机。在 Acceptor 字符串中,它可以是 0 ('host=0'),这意味着接受所有可用网络接口。 | |
| port | 要侦听/连接的 TCP/IP 端口号。 | |
| tcpNoDelay | 对应于套接字选项 tcpNoDelay。对于 UNO 连接,应将此参数设置为 1 (这不是默认值 ― 必须明确添加此数)。如果使用默认值 (0),在某些调用组合中可能会发生 200 毫秒的延迟。 | |
| 管道 | 命名管道(使用共享内存)。此进程间连接类型比套接字连接稍微快一些,并仅适用于两个进程位于同一台计算机的情况。默认情况下,此连接类型不适用于 Java,因为 Java 不直接支持命名管道 | |
| 参数 | 说明 | |
| name | 命名管道的名称。一台计算机一次只能接受一个进程名称。 | |
| Content on this page is licensed under the Public Documentation License (PDL). |