Published: 10 Jan 2018 › Updated: 10 Jan 2018

V2Ray 互操作简介(之一)
V2Ray 自即日起提供了一些简易的 API,以方便其它开发人员将 V2Ray 集成在自己的项目中。话不多说,直接上代码。
首先,你需要一个配置。其中dispatcher和proxyman.Outbound是必需的,一个负责分发请求,一个负责管理传出连接。另外还需要一个具体的传出协议,这里使用socks,只是为了方便测试。
config := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&dispatcher.Config{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
},
Outbound: []*core.OutboundHandlerConfig{{
ProxySettings: serial.ToTypedMessage(&socks.ClientConfig{
Server: []*protocol.ServerEndpoint{{
Address: net.NewIPOrDomain(net.ParseAddress("162.243.108.129")),
Port: 1080,
}},
})},
},
}
然后根据上述的配置创建一个 V2Ray 的实例:
v, err := core.New(config)
然后就可以创建连接了:
conn, err := core.Dial(
context.Background(),
v,
net.TCPDestination(
net.ParseAddress("www.v2ray.com"),
net.Port(80)))
这段代码表示使用我们刚刚创建的 V2Ray 实例,新建一个指向 v2ray.com:80 的传出连接。当然了,这当中还会使用配置中指定的 socks 代理。在拿到Dial返回的conn对象之后,可以进行数据传输了。
完整的代码可以在这里找到。
Leave V2Ray 互操作简介(之一) to:
Read more #cn posts
Best Posts From Victoria Raymond
We have not curated any of v2ray's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.