next up previous contents
Next: Contributed Servers Up: Operation Specific Functionality and Previous: Logging   Contents

Setting Up an OPC Server Instance

As the server classes of PyOPC are based on the Twisted framework, it is also utilized to set up the OPC server instance. This can be done as shown in listing 11, which implies the proper definition of the class ``MyXDAServer'', as already shown in listing 9.

language=C
\begin{lstlisting}[caption={Instantiating and Starting a PyOPC-based
OPC XML-DA ...
...= server.Site(root)
reactor.listenTCP(8000, site)
reactor.run()
\end{lstlisting}

Line 1-2 import all needed Twisted modules and create the PyOPC server object. In line 3, a Twisted resource object is created, where servers can be added, such as shown in line 4. Line 5-7 then starts the server. This server will then be reachable under the address ``http://server:8000/''.

A Twisted resource.Resource object is not limited to one PyOPC server instance, instead it is possible to add multiple server objects, such as shown in listing 12, which are then reachable under different URLs.

language=C
\begin{lstlisting}[caption={Adding Multiple PyOPC Server Objects to
One Twisted ...
...ild('srv2',MyXDAServer2())
root.putChild('srv3',MyXDAServer3())
\end{lstlisting}



Hermann Himmelbauer 2006-11-07