/**
   * Send packet to the server
   *
   * @param func
   * @param cmd
   * @return
   */
  public static String sendPacket(String func, String cmd) {
    String res = "";
    Packet packet = new Packet();

    socket = Client_tcp.getInstance();
    if (socket.getIsConnected() || socket.connect(Constants.SERVER_IP, Constants.SERVER_PORT)) {
      packet.setDest(1);
      packet.setSrc(2);
      packet.setData(cmd);
      packet.setFunc(func);
      socket.send(packet.getHeader());
      socket.send(cmd);
      res = socket.receive();
    }
    return (res);
  }
Exemplo n.º 2
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] msg = {"0", "", "", "", "", "", "", ""};
    CH = new Custom_Handler(1);
    send_packet = new Packet();
    send_packet.setType(1);
    send_packet.setData(msg);
    Log.d("Get_Statistics", "write on send_packet");

    elec_thread = new Elec_Client(CH, send_packet);

    try {
      elec_thread.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }