Exemple #1
0
  public static void reset() {
    // network@ip:10002
    String address = source.substring(8, source.length() - 6);

    try {
      Socket server = new Socket(address, 9999);
      DataOutputStream out = new DataOutputStream(server.getOutputStream());
      out.writeBytes("\r\n");
      out.flush();
      out.writeBytes("9\r\n");
      out.flush();
    } catch (Exception e) {
      System.out.println("Sorry I can't reset the device fro some reason: " + e);
      System.exit(1);
    }
    System.out.println("Issued reset command to " + address);
  }
Exemple #2
0
 public static void httpWrite(HttpURLConnection cx, String data)
     throws IOException, ProtocolException {
   cx.setDoOutput(true);
   DataOutputStream wr = new DataOutputStream(cx.getOutputStream());
   wr.writeBytes(data);
   wr.flush();
   wr.close();
 }
  /* Envoi d'un message au client */
  public void SendMsg(String msg) {
    String chargeUtile = msg;
    int taille = chargeUtile.length();
    StringBuffer message = new StringBuffer(String.valueOf(taille) + "#" + chargeUtile);

    try {
      dos.write(message.toString().getBytes());
      dos.flush();
    } catch (IOException e) {
      System.err.println("RunnableTraitement : Erreur d'envoi de msg (IO) : " + e);
    }
  }
Exemple #4
0
  public static void main(String[] ar) {

    int port = 6000;
    Date sysDate = new Date();
    String sysDateStr2;
    sysDateStr2 = new SimpleDateFormat("yyyy-MM-dd").format(sysDate).toString();
    try {
      ServerSocket ss = new ServerSocket(port);
      System.out.println("Waiting for a client to connect...");
      System.out.println("client connected");
      System.out.println();

      String msg = null;
      String IP, Date;
      float upload, download;
      Socket socket = ss.accept();
      InputStream sin = socket.getInputStream();
      OutputStream sout = socket.getOutputStream();
      DataInputStream in = new DataInputStream(sin);
      DataOutputStream out = new DataOutputStream(sout);
      while (true) {

        msg = in.readUTF(); // wait for the client to send a line of text.
        System.out.println("IP address:" + msg);
        IP = msg;
        msg = in.readUTF();
        System.out.println("Upload:" + msg);

        upload = Float.parseFloat(msg);
        msg = in.readUTF();
        System.out.println("Download:" + msg);
        download = Float.parseFloat(msg);
        System.out.println("Date:" + sysDateStr2);
        Date = sysDateStr2;
        recieveTrafficRates(IP, upload, download);
        out.writeUTF(msg);
        // in.read(b);
        out.flush();
        System.out.println("Waiting for the next line...");
        System.out.println();
      }

    } catch (Exception x) {

      x.printStackTrace();
    }
  }
  /**
   * Method declaration
   *
   * @param b
   * @throws IOException
   */
  void write(byte b[]) throws IOException {

    mOutput.writeInt(b.length);
    mOutput.write(b);
    mOutput.flush();
  }