1.In general, it is more efficient for the application to write large messages and have them fragmented and reassembled by IP, than to have the application write multiple times.
原因就在于系统调用system_call从应用态转到内核态等系列复杂过程带来的性能的损耗
2.tcp_sendspace
TCP send buffer size can limit how much data the application can send before the application is put to sleep. The TCP socket send buffer is used to buffer the application data in the kernel using mbufs/clusters before it is sent beyond the socket and TCP layer. The default size of this buffer is specified by the parameter tcp_sendspace, but you can use the setsockopt() subroutine to override it.
If the amount of data that the application wants to send is smaller than the send buffer size and also smaller than the maximum segment size and if TCP_NODELAY is not set, then TCP will delay up to 200 ms, until enough data exists to fill the send buffer or the amount of data is greater than or equal to the maximum segment size, before transmitting the packets.
If TCP_NODELAY is set, then the data is sent immediately (useful for request/response type of applications). If the send buffer size is less than or equal to the maximum segment size (ATM and SP switches can have 64 K MTUs), then the application's data will be sent immediately and the application must wait for an ACK before sending another packet (this prevents TCP streaming and could reduce throughput).
TCP发送数据时首先要看发送缓冲区是否有足够的空间存放待发送消息,如果有则复制到发送缓冲区,并且需要等待ack回来才会删除该数据,如果发送缓冲区没有足够空间则会等待或者返回EWOULDBLOCK(非阻塞) ----TCPv2
Note: To maintain a steady stream of packets, increase the socket send buffer size so that it is greater than the MTU (3-10 times the MTU size could be used as a starting point).
If an application does nonblocking I/O (specified O_NDELAY or O_NONBLOCK on the socket), then if the send buffer fills up, the application will return with an EWOULDBLOCK/EAGAIN error rather than being put to sleep. Applications must be coded to handle this error (suggested solution is to sleep for a short while and try to send again).
分享到:
相关推荐
用其它的工具没有调试成功,用此工具调试成功了,所以就留一份备用。
TCP socket服务端代码 C# 用于GPRS的服务端测试程序
查看本机tcp socket当前连接数(并发量).zip
最近有个项目模块需要用到TCP Socket通讯,遇到了一个大坑,所以做了这个Demo。 本Demo主要实现了安卓(Android)TCP 客户端(Client)和服务器(Server)Demo的Socket通讯。以及对接硬件的项目数据在十六进制&&byte&&int...
简单tcp socket 客户端 服务端代码实现 附C++代码源码
Tcp Socket client 事件驱动,与界面分开。
tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序tcp socket 聊天程序
C# TCP Socket 通讯 实例 客户端服务端,仅学习使用 C# TCP Socket 通讯 实例 客户端服务端,仅学习使用
一个简单的TCP服务器框架,通用性强,上手快,稍作修改即可用于工程
基于TCP,socket通信,简单小程序,很适合初学者
模拟TCP请求或简单的socket请求报文发送工具,免安装绿色版本
TCP SOCKET多线程通信,使用.NET自带线程池,高效率 ,可用来测试端口防火墙等,注释详细,
这个小demo是基于QT5编写的,采用TCP SOCKET通信方式,分为client和server端,有简单的界面,可进行信息发送与接收。
QT5.1做的WIN32 TCPsocket的2个对话框例子,有注释.库已有,qmake,再改一下客户端IP就可以用
c# tcpsocket 原生代码编写 客户端和服务端程序
TCPsocket源码,以选择模式写的双客户端,与服务器之间的通信
tcp socket客户端通讯插件,提供了几个必要的接口,跟服务器进行通讯。
自己封装的TCPSocket,用于自建C++编程
C# TCP Socket 分包传送数据,这个代码也是从别的地方淘来的,用的还不错。
TCP socketDemo