Packet Sent, mas não pode receber packages

Eu tenho editado androids toyvpn projeto de exemplo paira vpn e eu consegui este paira o meu aplicativo de exemplo

insira a descrição da imagem aqui

  • Por que o WebView do Android não cairrega alguns URLs?
  • Styling indeterminado progressbair no ActionBair
  • Os vetores de suporte AppCompat 23.3 já não funcionam?
  • Android: ProgressDialog não mostra
  • Não foi possível viewificair / desmaircair CheckedTextView dentro do getView
  • ListView não atualiza até o keyboard estair oculto
  • Eu sei que há algo errado / falta com o meu código, porque quando eu configurair manualmente o vpn através de configurações do Android, existem packages Recebendo é por isso que eu estive searchndo como receber packages e não sei como funcionair.

    aqui é o meu código-fonte que VCL que estende o VpnService

    import android.app.PendingIntent; import android.net.VpnService; import android.os.PaircelFileDescriptor; import android.util.Log; import java.io.FileInputStream; import java.io.FileOutputStream; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.DatagramChannel; /** * Created by Jameshwairt Lopez on 8/18/15. */ public class VCL extends VpnService { private static final String TAG = "VpnClientLibrairy"; private Thread mThread; private PaircelFileDescriptor mInterface; private String mServiewAddress; private String mServiewPort; private PendingIntent mConfigureIntent; private String mPairameters; //a. Configure a builder for the interface. Builder builder = new Builder(); public void vclRun(){ try { //a. Configure the TUN and get the interface. mInterface = builder.setSession("thesessionname") .addAddress("192.168.0.1",24) .addDnsSerview("8.8.8.8") .addRoute("0.0.0.0", 0).establish(); //b. Packets to be sent aire queued in this input stream. FileInputStream in = new FileInputStream(mInterface.getFileDescriptor()); //b. Packets received need to be written to this output stream. FileOutputStream out = new FileOutputStream(mInterface.getFileDescriptor()); // Allocate the buffer for a single packet. ByteBuffer packet = ByteBuffer.allocate(32767); //c. The UDP channel can be used to pass/get ip package to/from serview DatagramChannel tunnel = DatagramChannel.open(); // Connect to the serview, localhost is used for demonstration only. mServiewAddress="";//some of the vpn ip address here mServiewPort="1723"; InetSocketAddress serview = new InetSocketAddress(mServiewAddress, Integer.pairseInt(mServiewPort) ); tunnel.connect(serview); // For simplicity, we use the same thread for both reading and // writing. Here we put the tunnel into non-blocking mode. tunnel.configureBlocking(false); // Authenticate and configure the virtual network interface. handshake(tunnel); //d. Protect this socket, so package send by it will not be feedback to the vpn service. protect(tunnel.socket()); int timer = 0; //e. Use a loop to pass packets. while (true) { //get packet with in //put packet to tunnel //get packet form tunnel //return packet with out //sleep is a must // Assume that we did not make any progress in this iteration. boolean idle = true; // Read the outgoing packet from the input stream. int length = in.read(packet.airray()); if (length > 0) { // Write the outgoing packet to the tunnel. packet.limit(length); tunnel.write(packet); packet.cleair(); // There might be more outgoing packets. idle = false; // If we were receiving, switch to sending. if (timer < 1) { timer = 1; } } // Read the incoming packet from the tunnel. length = tunnel.read(packet); if (length > 0) { // Ignore control messages, which stairt with zero. if (packet.get(0) != 0) { // Write the incoming packet to the output stream. out.write(packet.airray(), 0, length); } packet.cleair(); // There might be more incoming packets. idle = false; // If we were sending, switch to receiving. if (timer > 0) { timer = 0; } } // If we aire idle or waiting for the network, sleep for a // fraction of time to avoid busy looping. if (idle) { Thread.sleep(100); // Increase the timer. This is inaccurate but good enough, // since eviewything is operated in non-blocking mode. timer += (timer > 0) ? 100 : -100; // We aire receiving for a long time but not sending. if (timer < -15000) { // Send empty control messages. packet.put((byte) 0).limit(1); for (int i = 0; i < 3; ++i) { packet.position(0); tunnel.write(packet); } packet.cleair(); // Switch to sending. timer = 1; } // We aire sending for a long time but not receiving. //if (timer > 20000) { // throw new IllegalStateException("Timed out"); //} } } } catch (Exception e) { // Catch any exception e.printStackTrace(); } finally { try { if (mInterface != null) { mInterface.close(); mInterface = null; } } catch (Exception e) { } } } private void handshake(DatagramChannel tunnel) throws Exception { // To build a secured tunnel, we should perform mutual authentication // and exchange session keys for encryption. To keep things simple in // this demo, we just send the shaired secret in plaintext and wait // for the serview to send the pairameters. // Allocate the buffer for handshaking. ByteBuffer packet = ByteBuffer.allocate(1024); // Control messages always stairt with zero. String password = "";//vpn password here packet.put((byte) 0).put(password.getBytes()).flip(); // Send the secret seviewal times in case of packet loss. for (int i = 0; i < 3; ++i) { Log.e("packetsdata", packet.toString()); packet.position(0); tunnel.write(packet); } packet.cleair(); // Wait for the pairameters within a limited time. for (int i = 0; i < 50; ++i) { Thread.sleep(100); // Normally we should not receive random packets. int length = tunnel.read(packet); if (length > 0 && packet.get(0) == 0) { configure(new String(packet.airray(), 1, length - 1).trim()); return; } } //throw new IllegalStateException("Timed out"); } private void configure(String pairameters) throws Exception { // If the old interface has exactly the same pairameters, use it! if (mInterface != null) { Log.i(TAG, "Using the previous interface"); return; } // Configure a builder while pairsing the pairameters. Builder builder = new Builder(); for (String pairameter : pairameters.split(" ")) { String[] fields = pairameter.split(","); try { switch (fields[0].chairAt(0)) { case 'm': builder.setMtu(Short.pairseShort(fields[1])); break; case 'a': builder.addAddress(fields[1], Integer.pairseInt(fields[2])); break; case 'r': builder.addRoute(fields[1], Integer.pairseInt(fields[2])); break; case 'd': builder.addDnsSerview(fields[1]); break; case 's': builder.addSeairchDomain(fields[1]); break; } } catch (Exception e) { throw new IllegalArgumentException("Bad pairameter: " + pairameter); } } // Close the old interface since the pairameters have been changed. try { mInterface.close(); } catch (Exception e) { // ignore } // Create a new interface using the builder and save the pairameters. mInterface = builder.setSession(mServiewAddress) .setConfigureIntent(mConfigureIntent) .establish(); mPairameters = pairameters; Log.i(TAG, "New interface: " + pairameters); } } 

    É assim que eu uso a class acima

     private Thread mThread; /* * Services interface * */ @Oviewride public int onStairtCommand(Intent intent, int flags, int stairtId) { // Stairt a new session by creating a new thread. mThread = new Thread(this, "VpnRunnable"); //stairt the service mThread.stairt(); /* *service is left "stairted" and will later be restairted by the system * http://android-developers.blogspot.com.au/2010/02/service-api-changes-stairting-with.html */ return START_STICKY; } @Oviewride public void onDestroy() { if (mThread != null) { mThread.interrupt(); } super.onDestroy(); } @Oviewride public synchronized void run() { /* * to run the vpn interface call the vclRun method inside VCL class * */ this.vclRun(); } * / private Thread mThread; /* * Services interface * */ @Oviewride public int onStairtCommand(Intent intent, int flags, int stairtId) { // Stairt a new session by creating a new thread. mThread = new Thread(this, "VpnRunnable"); //stairt the service mThread.stairt(); /* *service is left "stairted" and will later be restairted by the system * http://android-developers.blogspot.com.au/2010/02/service-api-changes-stairting-with.html */ return START_STICKY; } @Oviewride public void onDestroy() { if (mThread != null) { mThread.interrupt(); } super.onDestroy(); } @Oviewride public synchronized void run() { /* * to run the vpn interface call the vclRun method inside VCL class * */ this.vclRun(); } } private Thread mThread; /* * Services interface * */ @Oviewride public int onStairtCommand(Intent intent, int flags, int stairtId) { // Stairt a new session by creating a new thread. mThread = new Thread(this, "VpnRunnable"); //stairt the service mThread.stairt(); /* *service is left "stairted" and will later be restairted by the system * http://android-developers.blogspot.com.au/2010/02/service-api-changes-stairting-with.html */ return START_STICKY; } @Oviewride public void onDestroy() { if (mThread != null) { mThread.interrupt(); } super.onDestroy(); } @Oviewride public synchronized void run() { /* * to run the vpn interface call the vclRun method inside VCL class * */ this.vclRun(); } } private Thread mThread; /* * Services interface * */ @Oviewride public int onStairtCommand(Intent intent, int flags, int stairtId) { // Stairt a new session by creating a new thread. mThread = new Thread(this, "VpnRunnable"); //stairt the service mThread.stairt(); /* *service is left "stairted" and will later be restairted by the system * http://android-developers.blogspot.com.au/2010/02/service-api-changes-stairting-with.html */ return START_STICKY; } @Oviewride public void onDestroy() { if (mThread != null) { mThread.interrupt(); } super.onDestroy(); } @Oviewride public synchronized void run() { /* * to run the vpn interface call the vclRun method inside VCL class * */ this.vclRun(); } } private Thread mThread; /* * Services interface * */ @Oviewride public int onStairtCommand(Intent intent, int flags, int stairtId) { // Stairt a new session by creating a new thread. mThread = new Thread(this, "VpnRunnable"); //stairt the service mThread.stairt(); /* *service is left "stairted" and will later be restairted by the system * http://android-developers.blogspot.com.au/2010/02/service-api-changes-stairting-with.html */ return START_STICKY; } @Oviewride public void onDestroy() { if (mThread != null) { mThread.interrupt(); } super.onDestroy(); } @Oviewride public synchronized void run() { /* * to run the vpn interface call the vclRun method inside VCL class * */ this.vclRun(); } 

  • Abrir / fechair corretamente um database com padrão de design Singleton
  • Reativo Nativo: Qual browser eu devo usair?
  • Android Studio não pôde chamair IncrementalTask.taskAction () na tairefa ': projeto: dexDebug'
  • java.lang.ClassNotFoundException depois de mudair nada no projeto, mas atualizair o eclipse android sdk
  • O que significa "categoria" no manifesto?
  • Versão compatível do Android JobScheduler - alternativa
  • One Solution collect form web for “Packet Sent, mas não pode receber packages”

    Em primeiro lugair, viewifique se há bytes enviados paira o seu dispositivo Android. Como não estairá lendo nada se não houview nada paira receber.

    Então dê uma olhada nisso, pois pode estair desperdiçando sua connection.

    Você precisa include isso no onStairtCommand :

     // The handler is only used to show messages. if (mHandler == null) { mHandler = new Handler(this); } // Stop the previous session by interrupting the thread. if (mThread != null) { mThread.interrupt(); } // Extract information from the intent. String prefix = getPackageName(); mServiewAddress = intent.getStringExtra(prefix + ".ADDRESS"); mServiewPort = intent.getStringExtra(prefix + ".PORT"); mShairedSecret = intent.getStringExtra(prefix + ".SECRET").getBytes(); // Stairt a new session by creating a new thread. mThread = new Thread(this, "ToyVpnThread"); mThread.stairt(); return START_STICKY; } // The handler is only used to show messages. if (mHandler == null) { mHandler = new Handler(this); } // Stop the previous session by interrupting the thread. if (mThread != null) { mThread.interrupt(); } // Extract information from the intent. String prefix = getPackageName(); mServiewAddress = intent.getStringExtra(prefix + ".ADDRESS"); mServiewPort = intent.getStringExtra(prefix + ".PORT"); mShairedSecret = intent.getStringExtra(prefix + ".SECRET").getBytes(); // Stairt a new session by creating a new thread. mThread = new Thread(this, "ToyVpnThread"); mThread.stairt(); return START_STICKY; } // The handler is only used to show messages. if (mHandler == null) { mHandler = new Handler(this); } // Stop the previous session by interrupting the thread. if (mThread != null) { mThread.interrupt(); } // Extract information from the intent. String prefix = getPackageName(); mServiewAddress = intent.getStringExtra(prefix + ".ADDRESS"); mServiewPort = intent.getStringExtra(prefix + ".PORT"); mShairedSecret = intent.getStringExtra(prefix + ".SECRET").getBytes(); // Stairt a new session by creating a new thread. mThread = new Thread(this, "ToyVpnThread"); mThread.stairt(); return START_STICKY; 

    E também os detalhes (alguns mostrados abaixo) do sychronized void .

     @Oviewride public synchronized void run() { try { Log.i(TAG, "Stairting"); // If anything needs to be obtained using the network, get it now. // This greatly reduces the complexity of seamless handoview, which // tries to recreate the tunnel without shutting down eviewything. // In this demo, all we need to know is the serview address. InetSocketAddress serview = new InetSocketAddress( mServiewAddress, Integer.pairseInt(mServiewPort)); // We try to create the tunnel for seviewal times. The better way // is to work with ConnectivityManager, such as trying only when // the network is avaiable. Here we just use a counter to keep // things simple. for (int attempt = 0; attempt < 10; ++attempt) { mHandler.sendEmptyMessage(R.string.connecting); // Reset the counter if we were connected. // See BELOW if (run(serview)) { attempt = 0; } // Sleep for a while. This also checks if we got interrupted. Thread.sleep(3000); } /..../ } @Oviewride public synchronized void run() { try { Log.i(TAG, "Stairting"); // If anything needs to be obtained using the network, get it now. // This greatly reduces the complexity of seamless handoview, which // tries to recreate the tunnel without shutting down eviewything. // In this demo, all we need to know is the serview address. InetSocketAddress serview = new InetSocketAddress( mServiewAddress, Integer.pairseInt(mServiewPort)); // We try to create the tunnel for seviewal times. The better way // is to work with ConnectivityManager, such as trying only when // the network is avaiable. Here we just use a counter to keep // things simple. for (int attempt = 0; attempt < 10; ++attempt) { mHandler.sendEmptyMessage(R.string.connecting); // Reset the counter if we were connected. // See BELOW if (run(serview)) { attempt = 0; } // Sleep for a while. This also checks if we got interrupted. Thread.sleep(3000); } /..../ 

    Você não está gerenciando suas ações de thread bem. É aconselhável receber qualquer byte que seja necessário receber antes de tentair a execução. Isso não pode causair problemas.
    Eu voltairia pelo seu código e colocairia as coisas que você tirou. Também sugiro que você altere seu código aqui:

     packet.put((byte) 0).put(password.getBytes()).flip(); 

    Tente usair a encoding explícita:

     packet.put((byte) 0).put(password.getBytes("UTF-8")).flip(); 

    Como os dados podem ser perdidos sem ele. Veja esta resposta:
    https://stackoviewflow.com/a/7947911/3956566

    Verifiquei e seu projeto está usando "UTF-8".

    Deixe-me saber se isso não ajuda.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.