I am trying to open a sender / receiver socket on the same device and send a 64k packet to the router then receive it back. The key is packet should go through router. So I will be able to tell user something about his local wifi speed. Here is what I tested:
InetAddress addr = InetAddress.getLocalHost();
datagramSocket = new DatagramSocket(SERVER_PORT, addr);
serverPacket = new DatagramPacket(data, MAX_BUFFER_SIZE, addr, CLIENT_PORT);
DatagramSocket clientSocket = new DatagramSocket(CLIENT_PORT, inetAddress);
DatagramPacket packet = new DatagramPacket(data, MAX_BUFFER_SIZE);
packet.setPort(SERVER_PORT);
datagramSocket.send(serverPacket);
clientSocket.receive(packet);
clientSocket.send(packet);
datagramSocket.receive(serverPacket);
As I said data is 64k byte. However above operation is finished in 2 milliseconds! So when I calculate totalPacketSize / elapsedTime result is huge! I think sockets share data on device, never going to router. Do you have suggestions?