UDP开发相关的一些心得
2010-03-12 13:27
274 查看
好久没接触过udp的底层开发了,需要做个udp server。由于client可能是固定端口发送过来的。不记得recvfrom是否可能一次接受多个package。翻了unp等书也没找到。就顺便研究了udp相关的一些问题。
1.关于rcvfrom是否可能获取多个package?
man udp
解答很明确如下:
All receive operations return only one packet. When the packet is
smaller than the passed buffer only that much data is returned, when it
bigger the packet is truncated and the MSG_TRUNC flag is set.
MSG_WAITALL is not supported.
也就是说一次只能接受一个package
2. SO_RCVBUF和SO_SNDBUF
每个套接口都有一个发送缓冲区和一个接收缓冲区。接收缓冲区被TCP和UDP用来将接收到的数据一直保存到由应用进程来读。
TCP:TCP通告另一端的窗口大小。TCP套接口接收缓冲区不可能溢出,因为对方不允许发出超过所通告窗口大小的数据。这就是TCP的流量控制,如果对方无视窗口大小而发出了超过宙口大小的数据,则接
收方TCP将丢弃它。
UDP:当接收到的数据报装不进套接口接收缓冲区时,此数据报就被丢弃。UDP是没有
流量控制的;快的发送者可以很容易地就淹没慢的接收者,导致接收方的UDP丢弃数据报。
max size的调试可以参考以下链接:
http://anotherbug.blog.chinajavaworld.com/entry/1222/0/60
tcp具体有2个参数
The per connection memory space defaults are set with two 3 element arrays:
These are arrays of three values: minimum, initial and maximum buffer size. They are used to set the bounds on autotuning and balance memory usage while under memory stress. Note that these are controls on the actual memory usage (not just TCP window size) and include memory used by the socket data structures as well as memory wasted by short packets in large buffers. The maximum values have to be larger than the BDP of the path by some suitable overhead.
UDP是以下两个参数
The maximum buffer size that applications can request (the maximum acceptable values for SO_SNDBUF and SO_RCVBUF arguments to the setsockopt() system call) can be limited with /proc variables:
The kernel sets the actual memory limit to twice the requested value (effectively doubling rmem_max and wmem_max) to provide for sufficient memory overhead. You do not need to adjust these unless your are planing to use some form of application tuning.
具体内核参数调试参看
For additional information on kernel variables, look at the documentation included with your kernel source, typically in some location such as /usr/src/linux-<version>/Documentation/networking/ip-sysctl.txt. There is a very good (but slightly out of date) tutorial on network sysctl's at http://ipsysctl-tutorial.frozentux.net/ipsysctl-tutorial.html.
1.关于rcvfrom是否可能获取多个package?
man udp
解答很明确如下:
All receive operations return only one packet. When the packet is
smaller than the passed buffer only that much data is returned, when it
bigger the packet is truncated and the MSG_TRUNC flag is set.
MSG_WAITALL is not supported.
也就是说一次只能接受一个package
2. SO_RCVBUF和SO_SNDBUF
每个套接口都有一个发送缓冲区和一个接收缓冲区。接收缓冲区被TCP和UDP用来将接收到的数据一直保存到由应用进程来读。
TCP:TCP通告另一端的窗口大小。TCP套接口接收缓冲区不可能溢出,因为对方不允许发出超过所通告窗口大小的数据。这就是TCP的流量控制,如果对方无视窗口大小而发出了超过宙口大小的数据,则接
收方TCP将丢弃它。
UDP:当接收到的数据报装不进套接口接收缓冲区时,此数据报就被丢弃。UDP是没有
流量控制的;快的发送者可以很容易地就淹没慢的接收者,导致接收方的UDP丢弃数据报。
max size的调试可以参考以下链接:
http://anotherbug.blog.chinajavaworld.com/entry/1222/0/60
tcp具体有2个参数
The per connection memory space defaults are set with two 3 element arrays:
1 2 | /proc/sys/net/ipv4/tcp_rmem - memory reserved for TCP rcv buffers /proc/sys/net/ipv4/tcp_wmem - memory reserved for TCP snd buffers |
UDP是以下两个参数
The maximum buffer size that applications can request (the maximum acceptable values for SO_SNDBUF and SO_RCVBUF arguments to the setsockopt() system call) can be limited with /proc variables:
1 2 | /proc/sys/net/core/rmem_max - maximum receive window /proc/sys/net/core/wmem_max - maximum send window |
具体内核参数调试参看
For additional information on kernel variables, look at the documentation included with your kernel source, typically in some location such as /usr/src/linux-<version>/Documentation/networking/ip-sysctl.txt. There is a very good (but slightly out of date) tutorial on network sysctl's at http://ipsysctl-tutorial.frozentux.net/ipsysctl-tutorial.html.
相关文章推荐
- 【Visual C++】一些开发心得与调试技巧
- 对于UDP的一些心得
- 游戏开发相关的一些中英文对照
- Java开发相关的一些优秀网站集锦
- 与JavaWeb开发相关的一些名词解释
- 关于WinCE开发的一些心得
- 【Visual C++】一些开发心得与调试技巧
- 在Linux上开发网络服务器的一些相关细节:poll与epoll
- 对于linux socket与epoll配合相关的一些心得记录
- JAVA开发:分享一些SpringMvc+Ibatis+spring的框架使用心得
- 图解 HTTP:Web开发相关的一些核心基础概念
- javascript插件开发的一些感想和心得
- 理解嵌入式开发中的一些硬件相关的概念
- 理解嵌入式开发中的一些硬件相关的概念
- 转自weiphone]在美做开发多年,写给国内apple开发新手的一些心得,无教程
- C语言笔试题的一些小探讨[2011年,硕士计算机相关职位笔试题 底层开发 嵌入式 FPGA等]
- openmeeting开发心得及相关文档
- 使用D2010开发DATASNAP的一些心得。
- 【小松教你手游开发】【unity实用技能】 unity 接WP8 sdk的一些心得
- 【Visual C++】一些开发心得与调试技巧