35
The
MessageConnection
can be opened in either server or client mode. A server
connection is opened by providing a URL that specifies an identifier (port number) for an
application on the local device for incoming messages.
(MessageConnection)Connector.open("sms://:6000");
Messages received with this identifier will then be delivered to the application by this
connection. A server mode connection can be used for both sending and receiving
messages. A client mode connection is opened by providing a URL which points to
another device. A client mode connection can only be used for sending messages.
(MessageConnection)Connector.open("sms://+441234567890
:6000");
SMS Port Numbers
When a port number is present in the address, the TP-User-Data of the SMS will contain
a User-Data-Header with the application port addressing scheme information element.
When the recipient address does not contain a port number, the TP-User-Data will not
contain the application port addressing header. The J2ME MIDlet cannot receive this kind
of message, but the SMS will be handled in the usual manner for a standard SMS to the
device.
When a message identifying a port number is sent from a server type
MessageConnection
, the originating port number in the message is set to the port
number of the
MessageConnection
. This allows the recipient to send a response to
the message that will be received by this
MessageConnection
.
However, when a client type
MessageConnection
is used for sending a message
with a port number, the originating port number is set to an implementation specific value
and any possible messages received to this port number are not delivered to the
MessageConnection
. Please refer to the section A.4.0 and A.6.0 of the JSR 120.
When a MIDlet in server mode requests a port number (identifier) to use and it is the first
MIDlet to request this identifier it will be allocated. If other applications apply for the same
identifier then an
IOException
will be thrown when an attempt to open
MessageConnection
is made. If a system application is using this identifier, the
MIDlet will not be allocated the identifier. The port numbers allowed for this request are
restricted to SMS messages. In addition, a MIDlet is not allowed to send messages to
certain restricted ports a
SecurityException
will be thrown if this is attempted.
JSR 120 Section A.6.0 Restricted Ports:
2805, 2923, 2948, 2949, 5502, 5503, 5508, 5511, 5512, 9200, 9201, 9203, 9207, 49996,
49999.