Motorola maxx V6 manual Draft Subject to Change 152/201, Socket Connection

Models: maxx V6

1 201
Download 201 pages 31.32 Kb
Page 152
Image 152

Java ME Developer Guide

Chapter 22 - Network APIs

CommConnection interface in the javax.microedition.io pack-

Supported

age

 

Dynamic DNS allocation through DHCP

Supported

HttpConnection interface in the javax.microedition.io.package.

Supported

HttpsConnection interface in the javaxmicroedition.io.package

Supported

SecureConnection interface in the

Supported

javax.microedition.io.package

 

SecurityInfo Interface in the javax.microedition.io.package

Supported

UDPDatagramConnection interface in the

Supported

javax.microedition.io.package

 

Table 29 Network API feature/class support for MIDP

Code Sample 8 shows the implementation of Socket Connection:

Socket Connection

import javax.microedition.io.*; import java.io.*;

import javax.microedition.midlet.*;

...

try {

//open the connection and io streams

sc = (SocketConnection)Connector.open ("socket://www.myserver.com:8080", Connector.READ_WRITE, true);

is = sc[i].openInputStream(); os = sc[i].openOutputStream();

}catch (Exception ex) { closeAllStreams();

System.out.println("Open Failed: " + ex.getMessage());

}

}

if (os != null && is != null)

{

try

{

os.write(someString.getBytes()); //write some data to server

int bytes_read = 0; int offset = 0;

int bytes_left = BUFFER_SIZE;

//read data from server until done

DRAFT - Subject to Change [152/201]

Page 152
Image 152
Motorola maxx V6 manual Draft Subject to Change 152/201, Socket Connection