I am using android Studio to develop an application, and I want to set the DSCP value in the IP header using UDP sockets. I follow this example .
import android.os.Message; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; public class UdpClientThread extends Thread{ String dstAddress; int dstPort; private boolean running; MainActivity.UdpClientHandler handler; DatagramSocket socket; InetAddress address; public UdpClientThread(String addr, int port, MainActivity.UdpClientHandler handler) { super(); dstAddress = addr; dstPort = port; this.handler = handler; } public void setRunning(boolean running){ this.running = running; } private void sendState(String state){ handler.sendMessage( Message.obtain(handler, MainActivity.UdpClientHandler.UPDATE_STATE, state)); } @Override public void run() { sendState("connecting..."); running = true; System.setProperty("java.net.preferIPv4Stack", "true"); try { socket = new DatagramSocket(); socket.setTrafficClass(128);
I searched on this forum and I found out that using System.setProperty("java.net.preferIPv4Stack", "true") , we can manipulate the DSCP values. But it doesn't seem to work on an Android app. How can I achieve the desired behavior? Am I missing something here? The code works without errors, but when I check the wiring (capturing the "any" interface and then applying the filter for udp) the value of the DSCP packet does not change. I am using an emulator on ubuntu 16 to test the script. Any help is appreciated.
java android android-studio udp sockets
Hassan abbas
source share