gpt4 book ai didi

java - 在VpnService中创建套接字会卡住线程

转载 作者:行者123 更新时间:2023-12-03 11:55:39 27 4
gpt4 key购买 nike

我正在尝试为Android实现无根防火墙。我已经解决了所有与SO相关的问题,但没有找到答案:

在这里,我正在配置我的VPN。

private void configure() {
// If the old interface has exactly the same parameters, use it!
if (mInterface != null) {
Log.i(TAG, "Using the previous interface");
return;
}

// Configure a builder while parsing the parameters.
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("192.168.178.90", 24);
//builder.addAddress("10.0.2.0", 32);
//builder.addDnsServer("8.8.8.8");
builder.addRoute("0.0.0.0", 0); // to intercept packets
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
mInterface = builder.establish();
}

然后我试图将数据发送到目标地址
byte[] data= new byte[pdata.data.capacity()];
pdata.data.get(data);


Socket s = new Socket(pdata.destAddr,pdata.destPort);

if(shouldBeBlocked(pdata.destAddr)) {
sendResult("blocked: "+ pdata.destAddr.toString()+":"+pdata.destPort);
} else {
sendResult(pdata.destAddr.toString()+":"+pdata.destPort);
if (protect(s)) {
...

但是线程在 Socket的构造函数上冻结,然后在rasinig IOException上冻结,如下所示:
java.net.ConnectException: failed to connect to /173.194.71.100 (port 443): connect failed: ETIMEDOUT (Connection timed out)

最佳答案

也许尝试builder.setMtu(1492);会更安全。参见http://en.wikipedia.org/wiki/Maximum_transmission_unit

关于java - 在VpnService中创建套接字会卡住线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com