UDP Connection Bundle

The UDP Connection Bundle wraps a connection factory implementing the datagram scheme. This scheme provides UDP based connection that can serve as an underlying layer for various protocols. It can be used by bundles which need communication with the local or remote OSGi framework.

Contents:


Bundle Information

Bundle JAR

The JAR file of this bundle is udpconn.jar, located in the bundles folder.

Import

Package Exporter Description
com.prosyst.util.ref ProSyst Util Bundle/ProSyst Util Full Bundle Allows storing log messages in the Log Service.
javax.microedition.io Connector Service Bundle/System Bundle Generic connection API.
org.mbs.services.io The ProSyst connection API. Provides means for creating connection listeners.
org.osgi.service.io The OSGi communication API.

Note: If the bundle is started on the Standard Version of the framework, the connection APIs are exported by the Connector Service Bundle. If the bundle is started on the Connector Version of the framework, these APIs are exported by the System Bundle.

Note: If the bundle is started on ProSyst mBS, the com.prosyst.util.ref package is exported by the ProSyst Util Bundle. If it is started on an OSGi framework provided by another vendor, the package is exported by the ProSyst Util Full Bundle.

Export

None.

Exported Services

UDP Connection Factory Service

This service publishes the org.osgi.service.io.ConnectionFactory interface and represents a connection factory for the OSGi communication model, described in the OSGi IO Connector Service Specification. It is used by the OSGi Connector Service (exported by the Connector Service Bundle or by the System Bundle, depending on the version of the framework) for creating connections over the datagram scheme.

The datagram scheme provides UDP-based connections using the standard Java platform API for UDP sockets (contained in the java.net package: DatagramSocket, DatagramPacket, etc.). It supports connections for sending and/or for receiving.

Each created connection implements two interfaces: javax.microedition.io.DatagramConnection, which is a subinterface of Connection, and ConnectionNotifier, which registers listeners for sending connections. A connection also extends java.util.Dictionary. The Dictionary is used to store connection-related properties (described later).

Note: It is not obligatory for both parties communicating over UDP to use the UDP Connection Factory Service. As the UDP Connection Factory Service implementation simply cares to open standard UDP sockets, connection-requester applications can communicate with any UDP socket opened on the specified host.

Note: If the connection factory is unregistered, all created connections are closed.

Datagram Uniform Resource Identifiers (URIs)

All URIs processed by the UDP connection factory must start with "datagram://". There are two types of URIs: for sending and for receiving.

datagram://<dest_host>:<port>[;<param>=<value>;<param>=<value>...]

where <dest_host> stands for the default destination host for sending the datagram packets. <port> stands for the port on which the UDP server receiving the datagrams is listening. Note that the local port for sending the datagrams is not specified in the sending type of URI. The [..] brackets show an optional part, they are not part of the URI itself. They show that the datagram URI can optionally have one or more parameters separated by semi-colon. <param> is the name of the parameter, <value> is its value. Parameters are listed in Table 1.

For example, a valid sending URI may look like this:

datagram://remote.psb:3333

Or the same URI with parameters:

datagram://remote.psb:3333;maxLength=1024;timeout=30000

<local_port> indicates the local port for sending (and receiving) packets. The optional parameters that can be passed to this URI are the same as the parameters for receiving connections. See Table 1.

Parameter Description
maxLength Defines the maximum allowed length of datagrams sent/received.
nomLength Defines the nominal length of datagram sent/received.
timeout The timeout in milliseconds for receiving.
Table 1: Parameters for the datagram URIs

Note: Some parts of the URI are case sensitive! For details, refer to RFC 2396.

Connection Properties

The Dictionary created by each connection contains the following list of properties:

Property Sending Connection Receiving Connection Description
local_port available available The local port to which the datagram connection is bound.
address available not available The address that will be used when a new datagram is created.
port available not available The remote port that will be used when a new datagram is created.
timeout optional optional The timeout in milliseconds. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

The UDP connection factory keeps all opened connections in a Dictionary. If the service gets unregistered, all connections are closed.

Using the Service

If you want to use the UDP Connection Factory Service as an underlying transport implementation for your connections, you must invoke the OSGi Connector Service, exported by the Connector Service Bundle, and pass a datagram URI to its open method. For more information refer to the Connector Service Bundle description. You can manage the created connections using the methods of the DatagramConnection and ConnectionNotifier subinterfaces of javax.microedition.io.Connection, and their connection properties using the values stored in the connection Dictionary.

System Properties

The UDP Connection Bundle owns two user-definable system properties. They serve for debug purposes.

System Property Description
mbs.io.udp.console If set to true, the log information messages created by the UDP Connection Bundle will be printed in the server's console. By default its value is false.
mbs.io.udp.debug If set to true, the messages at DEBUG level created by the UDP Connection Bundle will be stored through the Log Service. By default its value is false.

If you set/change these properties after the bundle has been activated, you must restart it so that it will accept the new values.

References


Connection Bundles