当代码在模拟器中执行时,当我开始服务并在浏览器应用中浏览网站时,它无法访问该网站并向我显示ERR_NAME_NOT_RESOLVED
。
请告诉我出错的问题。
FileInputStream in = new FileInputStream(
mInterface.getFileDescriptor());
FileOutputStream out = new FileOutputStream(
mInterface.getFileDescriptor());
DatagramChannel tunnel = DatagramChannel.open();
tunnel.connect(new InetSocketAddress("127.0.0.1", 8087));
Log.e("Localhost:",InetAddress.getLocalHost().toString());
protect(tunnel.socket());
Log.e("MyVpnJavaClass", "protected tunnel");
ByteBuffer packet = ByteBuffer.allocate(32767);
Log.e("MyVpnJavaClass", "Byte Buffer packets");
int timer = 0;
Thread.sleep(100);
以上代码正常工作,LOGCAT
显示为“BYTE BUFFER PACKETS”。但在while循环中,它不会显示所有LOGCAT
消息。请纠正我的问题
while(true) {
Log.e("MyVpnJavaClass", "while is true");
boolean idle = true;
int length = in.read(packet.array());
if (length > 0) {
Log.e("MyVpnJavaClass", "Lenght is > 0");
packet.limit(length);
Log.e("MyVpnJavaClass", "LIMITING Lenght");
DatagramPacket datagramPacket = new DatagramPacket(packet.array(),packet.array().length);
byte[] dataInThePacket = datagramPacket.getData();
System.out.println(DatagramSocketService.stringFromPacket(datagramPacket));
Log.e("MyVpnJavaClass", "system");
TCPPacket tcpPacket = new TCPPacket(0,packet.array());
int sourcePort = tcpPacket.getSourcePort();
String destAddress = tcpPacket.getDestinationAddress();
int destPort = tcpPacket.getDestinationPort();
Log.e("MyVpnJavaClass", "TCPPacket");
datagramPacket.setSocketAddress(new InetSocketAddress("127.0.0.1", 8087));
Log.e("MyVpnJavaClass", "datagram packet");
UDPPacket udpPacket = new UDPPacket(0, packet.array());
System.out.println("TCP Source port: " + );
System.out.println("TCP Destination port: " + );
System.out.println("TCP Destination address: " +);
System.out.println("Length of data: " + );
Log.e("MyVpnJavaClass", "System out commands");
System.out.println(" ");
System.out.println("UDPPacket destination address: " +);
System.out.println("UDPPacket destination port: " +);
System.out.println("IP Protocol: " + );
System.out.println("Length of data: " + );
Log.e("MyVpnJavaClass", "UDP Packets");
tunnel.write(packet);
packet.clear();
Log.e("MyVpnJavaClass", "Write & Clear");
idle = false;
if (timer < 1) {
timer = 1;
}
}
答案 0 :(得分:-1)
尝试一次检查程序的一部分。 即使我正在研究类似的项目,也有类似的问题。 我尝试在in.read之后立即编写tunnel.write()并且它有效。 我搜索了它为什么会发生但没有得到任何答案