title: How can I measure the transmission time between two android devices?
body: <p>I would like to monitor Wifi-Direct network (Bandwidth, latency etc). How can I measure the time it takes for X bytes to be received over a network (wifi direct). I mean <strong>TX + over the network + RX</strong> time.</p>
  
  <p>In DMMS (android Studio)I found the option of Network Statistics but here it is only shown transmission and reception time (and it is not very accurate because it appears on a graph).</p>
  
  <p>I had thought about using System.currentTimeMillis() but I have not found how to synchronize the clocks of both devices.</p>
  
  <p>TX:</p>
  
  <pre><code>                socket.bind(null);
                  socket.connect((new InetSocketAddress(host, port)), SOCKET_TIMEOUT);
                  int tamMensaje= 1024*1024; // 1 MB
                  byte[] bitAleatorio = new byte [tamMensaje]; // 1 byte [-128 a 127
                  for (int x=0;x&lt;bitAleatorio.length;x++){
                      bitAleatorio[x] =(byte) Math.round(Math.random());
                  }
  
                  DataOutputStream DOS = new DataOutputStream(socket.getOutputStream());
  
                  for(int i=0;i&lt;1024;i++){
                      DOS.write(bitAleatorio,(i*1024),1024);
                            }
  </code></pre>
  
  <p>RX:</p>
  
  <pre><code>                            ServerSocket serverSocket = new ServerSocket(SERVERPORT);
                              Socket client = serverSocket.accept();
                              DataInputStream DIS = new DataInputStream(client.getInputStream());
  
                              int tamMensaje= 1024*1024;
                              byte[] msg_received2= new byte [tamMensaje];
                          for(int i=0;i&lt;1024;i++){
                              DIS.read(msg_received2,(i*1024),1024);
                          }
                              client.close();
                              serverSocket.close();
  </code></pre>
  
  <p>Thanks</p>