Motorola C381P Benutzerhandbuch
![Motorola](https://files.manualsbrain.com/attachments/83de88ba2280e7232128e8931d7cbd2a38dcc654/common/fit/150/50/0293f422c4d32e7e0f777d5e11bc33c83ea5627f71ddf155374c02a23d9a/brand_logo.png)
8
Network APIs
Network APIs
31
SecureConnection interface in the javax.microedition.io.package
Supported
SecurityInfo Interface in the javax.microedition.io.package
Supported
ServerSocketConnection interface in the javax.microedition.io.package Supported
UDPDatagramConnection interface in the
javax.microedition.io.package
javax.microedition.io.package
Supported
Table 6 Network API feature/class support for MIDP 2.0
The Code Sample 2 shows the implementation of Socket Connection:
Socket Connection
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.midlet.*;
….
try {
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;
(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
do
{
bytes_read = is.read(buffer, offset,
bytes_left);
if (bytes_read > 0)
{
offset += bytes_read;
bytes_left -= bytes_read;
}
{
bytes_read = is.read(buffer, offset,
bytes_left);
if (bytes_read > 0)
{
offset += bytes_read;
bytes_left -= bytes_read;
}