wiki:AvangoConnectModule

Module: avango-connect

The module "avango-connect" provides the functionality to connect fields across the network. This is only a very lightweight mechanism with limited capabilities. More sophisticated mechanisms are provided by the avango-core module. For the communication, a simple ASCII protocol is used which makes it easy to use avango-connect as a bridge to non-AVANGO applications. As a convenience, there is a directory in the AVANGO source code which contains an implementation of avango-connect which is written in C#.

Input and Ouput Nodes

To connect fields across the network, it is not possible to connect them directly with the standard field connection mechanism. Instead, proxy nodes are needed which act as the network interface. There are two proxy node types: an InputNode is acting as an input interface and an OutputNode is acting as an output interface. To define an interface, a class must be derived from one of these node types. Changes in the data of one of the fields contained in the derived class will be exchanged across the network with the fields of another node on the other side, which is derived from the opposite proxy node type. This way, a connection between fields with the same name is established.

Because of the simple design of avango-connect, only a small set of field types are supported and there is no generic mechanism to transmit every possible field type that can be created with AVANGO. If there is a need for other field types, you have to write dedicated code for it to enhance avango-connect. But this should only be done, if that field type is very generic. If you need more advanced functionality, using the distribution feature of avango-core is probably a better place to start.

The following list shows the supported field types. At this time, there is only a small subset of the existing types, which grows on demand.

  • SFBool
  • SFInt
  • SFFloat
  • SFDouble
  • SFString
  • SFVec4
  • SFMatrix
  • MFInt
  • MFString
  • MFVec2
  • MFVec3
  • MFMatrix
# a node that receives data
class Input(avango.connect.InputNode):
    Text = avango.SFString()

# a node that sends data
class Output(avango.connect.OutputNode):
    Text = avango.SFString()

Implementing the Server Side

On the server side, the only thing to do is to create a Server object and assign it to the input and output nodes. At this time, it is only allowed to use no more than one single input and output node, each. Otherwise the behavior is undefined.
The Server node must be created by the listening host.

# a node that receives data (from a client)
class Input(avango.connect.InputNode):
    Text = avango.SFString()

# a node that sends data (to a client)
class Output(avango.connect.OutputNode):
    Text = avango.SFString()

server = avango.connect.Server(port=19901)

input_node = Input()
output_node = Output()

input_node.set_stream(server)
output_node.set_stream(server)

Implementing the Client Side

On the client side, the only thing to do is to create a "Client" object and assign it to the input and output nodes. At this time, it is only allowed to use no more than one single input and output node, each. Otherwise the behavior is undefined.
The Client node must be created by the connecting host.

# a node that receives data (from a server)
class Input(avango.connect.InputNode):
    Text = avango.SFString()

# a node that sends data (to a server)
class Output(avango.connect.OutputNode):
    Text = avango.SFString()

client = avango.connect.Client(host="localhost", port=19901)

input_node = Input()
output_node = Output()

input_node.set_stream(client)
output_node.set_stream(client)

Network Protocol

The values of the fields are sent over a TCP connection with a simple stream based text protocol. Every line of text carries the information of one single field and ends in a line feed (ASCII code 0x0a). The different parts of a line are separated by NUL characters (ASCII code 0x00).

Text<NUL>SFString<NUL>This is a test<LF>
Translation<NUL>SFVec4<NUL>1<NUL>2<NUL>3<NUL>4<LF>

In this example, the information about two fields is sent:

  • A field called "Text" of type "SFString" containing the text "This is a text".
  • A field called "Translation" of type "SFVec4" containing the value "(1, 2, 3, 4)".