예제 #1
0
파일: LibRt.java 프로젝트: yamila87/rt_src
 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();
 }
예제 #2
0
  /* 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);
    }
  }
예제 #3
0
파일: Main.java 프로젝트: manjunathgk22/BM
  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();
    }
  }
예제 #4
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);
  }
  /**
   * Method declaration
   *
   * @param b
   * @throws IOException
   */
  void write(byte b[]) throws IOException {

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