Java User’s Guide
13.1 Using the AT Command API
122
s
wm_java_usersguide_v12
Page 115 of 123
2008-02-25
Confidential / Released
13.1.1.3
Data Connections
If a data connection is created with the
ATCommand
class, for instance with
‘
atd
’
, an input
stream is opened to receive the data from the connection. Similarly, an output stream can be
opened to send data on the connection.
/* Please note that this example would not work unless the module had
* been initialized and logged into a network. */
System.out.println("Dialing: ATD" + CALLED_NO);
response = atc.send("ATD" + CAL "\r");
System.out.println("received: " + response);
if (response.indexOf("CONNECT") >= 0) {
try {
// We have a data connection, now we do some streaming...
// IOException will be thrown if any of the Stream methods fail
OutputStream dataOut = ATCmd.getDataOutputStream();
InputStream dataIn = ATCmd.getDataInputStream();
// out streaming...
dataOut.write(new String("\n\rHello world\n\r").getBytes());
dataOut.write(new String("\n\rThis data was sent by a Java " +
"MIDlet!\n\r").getBytes());
dataOut.write(new String("Press 'Q' to close the " +
"connection\n\r").getBytes());
// ...and in streaming
System.out.println("Waiting for incoming data, currently " +
dataIn.available() + " bytes in buffer.");
rcv = 0;
while(((char)rcv != 'q') && ((char)rcv != 'Q') && (rcv != -1)){
rcv = dataIn.read();
if (rcv >= 0) {
System.out.print((char)rcv);
}
}
/* The example continues after the next block of text */