Motorola E680 Technical Manual - Page 42

Socket Connection

Page 42 highlights

Connector class in the javax.microedition.io.package Dynamic DNS allocation through DHCP Supported Supported HttpConnection interface in the javax.microedition.io.package. Supported HttpsConnection interface in the javaxmicroedition.io.package Supported 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 Supported The following is a code sample to show 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 do { bytes_read = is.read(buffer, offset, 42

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107

42
Connector class in the javax.microedition.io.package
Supported
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 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
Supported
The following is a code sample to show 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
do
{
bytes_read = is.read(buffer, offset,