关于UNIX 网络编程中存在的疑惑。先写下来,等待解决

来源:互联网 发布:阿里云邮箱收发服务器 编辑:程序博客网 时间:2024/05/21 05:43

2-11  UDP Output

 

A UDP socket has a send buffer size (which we can change with the SO_SNDBUF socket option, Section 7.5), but this is simply an upper limit on the maximum-sized UDP datagram that can be written to the socket. If an application writes a datagram larger than the socket send buffer size, EMSGSIZE is returned.

 

 

在这段话中,我进行了试验。

 SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0);
 int nRes = 0;
 SOCKADDR_IN addrSrv;
 addrSrv.sin_addr.S_un.S_addr=inet_addr("172.16.1.32");
 addrSrv.sin_family=AF_INET;
 addrSrv.sin_port=htons(6000);

 int rcvbuf = 1024; 
 int optlen = sizeof(rcvbuf);
 nRes = setsockopt(sockClient,SOL_SOCKET,SO_SNDBUF,(char *)&rcvbuf,sizeof(int));
 
 if (SOCKET_ERROR == nRes)
 {
       printf("Client setsockopt error :%d /n",GetLastError());
 }


 char szSendBuf[10000] = "Hello";
 nRes =  sendto(sockClient,szSendBuf,10000,0,
  (SOCKADDR*)&addrSrv,sizeof(SOCKADDR));

 if (nRes == SOCKET_ERROR)
 {
      printf("send err..");
 }

 

但是,实际上的结果(调试结果却意外的是):sendto 成功,并实际发送了 10000个字节。按照上面的内容来说,应该是 返回 EMSGSIZE。为什么?

 

7-5  SO_RCVBUF and SO_SNDBUF Socket Options

 

The receive buffers are used by TCP, UDP, and SCTP to hold received data until it is read by the application.With TCP, the available room in the socket receive buffer limits the window that TCP can advertise to the other end。

 

设置SERVER端的 接收缓冲区大小为 10240字节之后,但是,从抓到的数据包来看。(MSS = 1460) 通告对方的窗口大小仍然为 65535 。为什么?

 

7-5  SO_RCVLOWAT and SO_SNDLOWAT Socket Options

UDP does not have a send buffer; it has only a send buffer size. 对于这句话,又当如何理解?

 

 

 

原创粉丝点击