Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DialWithOptionsAndLocal method #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ProtossGenius
Copy link

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
@ProtossGenius
Copy link
Author

Some requirements may need to specify a local address, such as intranet penetration

@codecov-io
Copy link

codecov-io commented Nov 29, 2019

Codecov Report

Merging #153 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@           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%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ed35ac...073b8c4. Read the comment docs.

@ProtossGenius
Copy link
Author

能够指定本地地址在某些时候或许会很有用,好像UDP内网穿透的时候就是从使用指定的端口的连接服务器开始的。

@xtaci
Copy link
Owner

xtaci commented Nov 29, 2019

为什么不用NewConn传入拨好的udpconn呢

@ProtossGenius
Copy link
Author

实际写起来的时候行数会有一点差别
用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)

不过就算不加的话在外面封装一个方法就行了,算是可有可无的吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants