kcp-go
kcp-go copied to clipboard
Added DialWithOptionsAndLocal method
Some requirements may need to specify a local address, such as intranet penetration
Some requirements may need to specify a local address, such as intranet penetration
Codecov Report
Merging #153 into master will increase coverage by
0.02%. The diff coverage is100%.
@@ Coverage Diff @@
## master #153 +/- ##
========================================
+ Coverage 75.98% 76% +0.02%
========================================
Files 10 10
Lines 2082 2084 +2
========================================
+ Hits 1582 1584 +2
Misses 418 418
Partials 82 82
| Impacted Files | Coverage Δ | |
|---|---|---|
| sess.go | 84.9% <100%> (+0.05%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 2ed35ac...073b8c4. Read the comment docs.
能够指定本地地址在某些时候或许会很有用,好像UDP内网穿透的时候就是从使用指定的端口的连接服务器开始的。
为什么不用NewConn传入拨好的udpconn呢
实际写起来的时候行数会有一点差别 用NewConn应该至少要写6~7行,新加一个方法的话一行就能搞定,最主要的是这样这个就能很容易的打洞了。
//外面拨的话会额外写 这么多的代码,基本上要写
udpaddr, err := net.ResolveUDPAddr("udp", raddr)
if err != nil {
//错误处理
}
network := "udp4"
if udpaddr.IP.To4() == nil {
network = "udp"
}
conn, err := net.ListenUDP(network, &net.UDPAddr{})
if err != nil {
//错误处理
}
conn, err := NewConn(raddr, block, dataShards, parityShards, conn)
不过就算不加的话在外面封装一个方法就行了,算是可有可无的吧。