Cep Terminals GSM/GPRS TERMINAL CT63 JAVA 6203 ユーザーズマニュアル

製品コード
6203
ページ / 109
Java User’s Guide
12.1 Using the AT Command API
109
wm_java_usersguide_v19
Page 102 of 109
2012-01-27
Confidential / Released
12.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" + CALLED_NO + "\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 */