Socket Connection Bundle

The Socket Connection Bundle wraps a Connection Factory implementing the socket scheme. This scheme provides TCP/IP based connection that can be used by 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 socketconn.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.

Socket 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 IO 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 socket scheme.

The Socket Connection Factory supports two types of connecton: server side and client side.

Note: It is not obligatory for both parties of the TCP/IP communication channel to use the Socket Connection Factory Service. As the Socket Connection Factory Service implementation simply cares to open client- or server-side sockets, the connection-requester applications can communicate with any server or client socket opened on the specified host. For example, if a service requests client connection through the URI: socket://remote.psb:888 (see Client-Side URIs), a connection will be established to the specified host on port 888, no matter if the port has been opened through the Socket Connection Factory Service or not.

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

Socket Uniform Resource Identifiers (URIs)

The URIs passed to client and server side connections slightly differ. The URI needed for a client socket connection must contain the address on which the server socket is opened.

All URIs processed by the Socket Connection Factory must start with "socket://".

Server-Side Socket URIs

A server-side URI is passed when we need to open a server socket listening on the specified port. The format of a server-side URI is:

socket://:<port>[;timeout=<millis>]

Where <port> stands for the occupied port number. The timeout=<millis> part is optional. If timeout is set, IOException will be thrown when the timeout expires.

Note: If zero is passed as a port value to a server side URI, the server socket will be bound to an arbitrary free port.

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

socket://:3333

Or, if we want to specify the connection timeout:

socket://:3333;timeout=50000

Client-Side Socket URIs

A client-side URI is passed when we need to establish connection with a server socket listening on some port. It requires the following syntax:

socket://<host>:<port>[;timeout=<millis>]

Where <host> stands for the IP addres or DNS name of the server you need to contact. <port> stands for the server port on which the server is listening for connections. The timeout=<millis> part is optional. If it is included, it will indicate a timeout in milliseconds for the connections. For example, a valid socket URI may look like this:

socket://test:333

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

Connection Properties

The Dictionary used by both client and server connections contains the following list of properties related to the connection:

Property Client Connection Server Connection Description
local_address available available The local address to which the socket is bound.
local_port available available The local port to which this socket is bound.
address available not available The address to which the socket is connected.
port available not available The remote port to which this socket is connected.
timeout optional optional The timeout in milliseconds. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

Using the Service

If you want to use the Socket 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 socket 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 respective subinterfaces of javax.microedition.io.Connection, and their connection properties using the values stored in the connection Dictionary. See Client-side connections and Server side connections for details.

System Properties

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

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

Used to close server side socket connections correctly - when close () of the server socket connection is called, then the close operation is delayed maximally with this timeout. This property is with lower priority than the one specified with the URI passed when opening a connection.

It is recommended that you use this property for the following OSs and VMs:

  • Red Hat Linux with JDK122_006
  • Red Hat Linux with JDK 131_002
  • Red Hat Linux with Jeode 1.8
  • Windows NT with Jeode 1.7
  • QNX with J9 1.5
  • VxWorks with Perc 3.2

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