"We have a Data Connection now we do some streaming" | Thales IoT Developer Community
August 14, 2014 - 12:24am, 3597 views
I'm a little confused about this point.
Source: Java User´s Guide
Version 19 Doc ID:wm_java_usersguide_v19
Products: TC65i,TC65i-X,EGS5,EGS5-X
Example
12.1.1.3 Data Connections
// we hava a data connection, now we do some streaming...
OutputStream dataOut = ATCmd.getDataOutputStream();
InputStream dataIn = ATCmd.getDataInputStream();
In the example, getDataOutputStream should returns a DataOutputStream Object instead of OutputStream object
and getDataInputStream should returns a DataInputStream Object instead of an InputStream object.
DataInputStream getDataInputStream()
DataOutputStream getDataOutputStream()
What is your suggestion? Am I wrong?
Regards
System.out.println("Dialin g: 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\r This 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);
}
}
/* continue example */
if (rcv != -1) {
// Now break the data connection
System.out.println ("\n\n\rBreaking connection");
try {
strRcv = ATCmd.breakConnection();
} catch(Exception e) {
System.out.println(e);
}
System.out.println("received: " + strRcv);
} else {
// Received EOF, somebody else broke the connection
System.out.println("\n\n\rSomebody else switched to " +
"command mode!");
}
System.out.println("Hanging up");
strRcv = ATCmd.send("ATH\r");
System.out.println("received: " + strRcv);
} catch(IOException e) {
System.out.println(e);
}
} else {
System.out.println("No data connection established,");
}