[Date Prev][Date Next][Thread Prev][Thread Next] - [Date Index][Thread Index][Author Index]

RE: Linux Predict Socket Server



Hi,

I've just got a simple client going which sends commands and
get the responses as in the c++ 'demo.c' NO error checking yet....

import java.io.*;
import java.net.*;

public class SocketTest {

  public static void main(String args[])
  {
      int port;
      InetAddress address;
      DatagramSocket socket = null;
      DatagramPacket packet;
      byte[] buf = new byte[256];

    try {

      if (args.length < 2)
      {
        System.out.println("Usage: java SocketTest <hostname> command
[sat]");
        return;
      }

      socket = new DatagramSocket();

      socket.setSoTimeout(1000);

      address = InetAddress.getByName(args[0]);

      String command = args[1];

      if (args.length == 3)
      {
        command = command + " " + args[2];
      }

      command = command + "\n";

      buf = command.getBytes();

      packet = new DatagramPacket(buf, buf.length,
                                           address, 1210);

      socket.send(packet);

      buf = new byte[255];
      packet = new DatagramPacket(buf, buf.length);
      socket.receive(packet);
      String outString = new String(packet.getData());

      System.out.println(outString);

    }
    catch(IOException e)
    {
      System.out.println("Error" + e);
    }
    finally
    {
      socket.close();
    }
  }
}

Now the fun begins......

D:\temp\jclient>java SocketTest dbserv GET_SAT ISS
ISS
194.18
-51.52
86.26
-86.12
995440102
4222.16
13080.68
366.06
27699.16
15193
D

I hope this sows a seed for other people..

- Dave

----
Via the amsat-bb mailing list at AMSAT.ORG courtesy of AMSAT-NA.
To unsubscribe, send "unsubscribe amsat-bb" to Majordomo@amsat.org



AMSAT Top AMSAT Home