作者simonxander (显显)
看板PangSir
标题Re: [ CN ] UDP sockets
时间Wed Nov 28 00:04:31 2012
※ 引述《suhorng ( )》之铭言:
: 想请问一下几个不确定的地方
: 我找到这篇 http://stackoverflow.com/questions/6189831/
: 所以使用 UDP 来传送资料时,
: (1) 对於 receiver, 我应该要用 bind 来主动把我的 port 绑定到一个我指定的位置
: (这样其他人可以指定送到这个 port, 那那些就会被我收到)
: (2) 对於 sender, 不必刻意调用 bind, 因为在 send/sendto/recv/recvfrom 时系统
: 会自动帮我 bind 某个固定的 port.
: (3) 因为 sender 传送资料(之类)後系统自动帮你 bind, 所以 receiver 可以照得到的
: source ip, port 原路传回去, 不会说 sender 两次传送是不同的 port, 造成资料
: 收不到的情况. sender 也可以主动先 bind, 只不过没必要.
: 请问这样理解正确吗?
是的,这样没错
receiver 在bind 时也请检查一下是否有成功,方便我们测试
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.53.209
1F:推 suhorng:谢谢! 11/28 00:11
2F:推 penknife211:可以请问一下为什麽receiver不用listen吗? 11/29 02:43
3F:→ simonxander:因为现在是用UDP传送,所以不需要 listen 和 connect 11/29 10:49
4F:→ simonxander:封包直接送出去即可 不用保证一定会送到或一定有人收 11/29 10:50
5F:推 penknife211:喔~助教谢谢~ 11/29 11:39