System information

Appendix D. JAVA Example Code
D-2
/**
* Application main
*/
public static void main(String[] args) {
try {
socket = new Socket("63.255.173.242", 23);
socket.setTcpNoDelay(true);
//The input streams and output streams are used through out
//this example for handling
//communication to/from the datalogger. In this
//example we are getting these streams
//from a socket, but the same streams can be initialized
//to talk over serial IO as well.
//The serial IO packages weren't included with the default
//JDK so we are using sockets here.
in_stream = new BufferedInputStream(new
DataInputStream(socket.getInputStream()));
out_stream = new DataOutputStream(socket.getOutputStream());
} catch( IOException e ) {
System.err.println( "SockConnection(), " + e );
if( socket != null ) {
try { socket.close(); }
catch( IOException ee ) {}
}
return;
}
SetupDL();
startscreen();
InputStreamReader stdin = new InputStreamReader(System.in);
boolean shouldExit = false;
try
{
while(!shouldExit)
{
if(in_stream.available() > 0)
{
in_packet = null;
GetLine(); // wait for a complete line
if(in_packet != null)
{
switch(((int)in_packet.message_type) & 0xFF)
{
case (0x97) :
System.out.println("Received clock check response");
ParseClk(); // Response for clock command body
SetClkCnts();
break;
case (0x89) : // Response for Collect Data Transaction
System.out.println("Response for Collect Data Transaction");
ParseDataCollectResp();
break;
case (0x87): // Response for Command format;
System.out.println("Response for Command format");
ParseCommand();
break;
case 0x9a:
ParsePublicTbl();
break;