Motorola i88s manual UDP Sockets, Serial Port Access

Page 18

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

Image 18
Contents I88s Multi-Communication Device J2ME Developers’ Guide J2ME Networking Document Overview DisclaimerContact Information Acronyms and DefinitionsAcronyms Used In This Guide Terminology Definition Agps On The i88s Phone OverviewPosition API AccuracyAssist Data PositionConnection Class Almanac Out Of DateExample GetPosition Method DescriptionsRetrieving Position in Java GetPositionString nameUsing Position in Java GetStatusExample Using PositionConnection Positionresponsenoalmanacoverride Addition, to obtain better accurate speed and direction Recommendation J2ME Networking Http Https Class Descriptions Http HttpsSupported Protocols on the i88s Phone TCP Sockets SSL Secure SocketsServerSockets Serial Port Access UDP SocketsConnection Optional Parameters Communicating on a PortExample using StreamConnection Implementation NotesTips Concurrent Connections For The i88s Phone Protocol MaximumFile I/O Class DescriptionMethod Descriptions Opening a file Deleting a file Reading and WritingCode Examples Example # 2 Complete MIDlet code Motorola Inc I88s J2ME Developers’ Guide Os = sc.openOutputStream //get InputStream Sc.close Caveats Motorola Inc I88s J2ME Developers’ Guide
Related manuals
Manual 43 pages 17.94 Kb