小编sha*_*ank的帖子

Android VpnService - 如何转发拦截的互联网流量?

我已经关注此链接并使用VpnService创建了Vpn接口.在将前向路由添加为"0.0.0.0"时,所有互联网流量都被转发到Vpn接口.我可以读取数据包,访问协议,目标IP和端口.

现在我试图通过tcp套接字将数据包转发到目的地.但是套接字连接失败并且连接超时.

exception: java.net.ConnectException: failed to connect to /74.125.227.114 (port 443): connect failed: ETIMEDOUT (Connection timed out)
Run Code Online (Sandbox Code Playgroud)

注意:当我尝试使用相同的ip和端口连接套接字但没有Vpn时,它会连接.无法弄清楚我哪里出错了?

粘贴下面的代码:

public class VpnServiceEx extends VpnService implements Handler.Callback, Runnable {
    private static final String TAG = "VpnServiceEx";

    private Handler mHandler;
    private Thread mThread;

    private ParcelFileDescriptor mInterface;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // The handler is only used to show messages.
        if (mHandler == null) {
            mHandler = new Handler(this);
        }

        // Stop the previous session …
Run Code Online (Sandbox Code Playgroud)

sockets vpn networking android tcp

6
推荐指数
1
解决办法
4730
查看次数

标签 统计

android ×1

networking ×1

sockets ×1

tcp ×1

vpn ×1