Motorola Inc.

i88s J2ME Developers’ Guide

returns a StreamConnectionNotifier. Unlike the other networking protocols, the StreamConnectionNotifier does not contain any accessor methods to retrieve data, but rather only one method to accept and open a Socket Connection. This method blocks until a Socket connection is available at which time, it returns a StreamConnection object. The following example illustrates this:

StreamConnectionNotifier scn = (StreamConnectionNotifier)Connector.open(“serversocket://:8000”);

StreamConnection sc = (StreamConnection)scn.acceptAndOpen();

The URL parameter passed in is similar to that used for TCP Sockets, with the exception of the target address. In this particular instance, the target address is left blank, assuming the serversocket is to be opened on the local device. The port number however, is still required. The acceptAndOpen() method of the StreamConnectionNotifier object is a blocking call, so applications that utilize the particular protocol, should take this into consideration.

Note - To close the serversocket, close the associated StreamConnectionNotifier.

2.2.6UDP Sockets

If networking efficiency is of greater importance than reliability, datagrams (UDP) sockets are also available to the application in much the same manner as other networking protocols. The Connector object in this case returns a DatagramConnection object, as is shown in the following example:

DatagramConnection dc = (DatagramConnection)Connector.open(“datagram://170.169.168.167:8000”);

Much like low-level sockets, accessing UDP requires both a target address and a port number. The i88s phone supports a maximum outgoing and incoming payload of 1472 bytes and 2944 bytes, respectively.

2.2.7Serial Port Access

Applications utilizing the bottom connector (serial port) to communicate with a variety of devices are given exclusive access to the port until either the application voluntarily releases the port or is terminated. Much like any other networking connection, opening a serial port is not guaranteed and an exception can be thrown. If another application native or Java is using the port, or a cable is not attached to the device, an IOException may be thrown. In the normal usage scenario, the Connector object in this instance returns a StreamConnection, as is shown in the following example:

StreamConnection sc = (StreamConnection)Connector.open(“comm:0;baudrate=19200;parity=n;datab its=8;stopbits=1;flowcontrol=n/n”);

Version 1.0 - Page 18

Page 18
Image 18
Motorola i88s manual UDP Sockets, Serial Port Access