错了!是在SOCKET的socketOptions里 /** * Set a hint the size of the underlying buffers used by the * platform for outgoing network I/O. When used in set, this is a * suggestion to the kernel from the application about the size of * buffers to use for the data to be sent over the socket. When * used in get, this must return the size of the buffer actually * used by the platform when sending out data on this socket. * * Valid for all sockets: SocketImpl, DatagramSocketImpl * * @see Socket#setSendBufferSize * @see Socket#getSendBufferSize * @see DatagramSocket#setSendBufferSize * @see DatagramSocket#getSendBufferSize */ public final static int SO_SNDBUF = 0x1001; /** * Set a hint the size of the underlying buffers used by the * platform for incoming network I/O. When used in set, this is a * suggestion to the kernel from the application about the size of * buffers to use for the data to be received over the * socket. When used in get, this must return the size of the * buffer actually used by the platform when receiving in data on * this socket. * * Valid for all sockets: SocketImpl, DatagramSocketImpl * * @see Socket#setReceiveBufferSize * @see Socket#getReceiveBufferSize * @see DatagramSocket#setReceiveBufferSize * @see DatagramSocket#getReceiveBufferSize */ public final static int SO_RCVBUF = 0x1002;
to airwing 我还是觉得与底层有关,因为setReceiveBuffer只是告诉JAVA系统设定一种缓冲机制 但数据总是要发送到网络上的。在物理层,存在一个最小发送长度,如通过ATM传送时好象是512个字节,你可以看看有关书籍,自然明白底层的运作
to kz 和物理层无关,任何应用层数据都会在IP层被分割层多个IP包,由TCP层负责传输和顺序、差错控制。难道各位做程序都只发512字节吗?
to airwing 是这样,例如TCP层发送数据513个字节,但你的网卡与下一个节点如中继器的通信有一个最小发送单位--比方512个字节。当TCP层flush()时物理层即网卡发送了两个数据包:一个512个字节;另一个也是512个字节(但只包含一个有用数据。当从另一端接收时,第一次read将512个字节放入了你的缓冲区(注意:接收必须是以数据包为单位),所以你必须再read一次
发送是0x1001个字节
接收是0x1002个字节那么大家继续讨论,在这种情况下,难道要我们自己来做底层的工作吗?大家有什么好办法
* Set a hint the size of the underlying buffers used by the
* platform for outgoing network I/O. When used in set, this is a
* suggestion to the kernel from the application about the size of
* buffers to use for the data to be sent over the socket. When
* used in get, this must return the size of the buffer actually
* used by the platform when sending out data on this socket.
*
* Valid for all sockets: SocketImpl, DatagramSocketImpl
*
* @see Socket#setSendBufferSize
* @see Socket#getSendBufferSize
* @see DatagramSocket#setSendBufferSize
* @see DatagramSocket#getSendBufferSize
*/
public final static int SO_SNDBUF = 0x1001; /**
* Set a hint the size of the underlying buffers used by the
* platform for incoming network I/O. When used in set, this is a
* suggestion to the kernel from the application about the size of
* buffers to use for the data to be received over the
* socket. When used in get, this must return the size of the
* buffer actually used by the platform when receiving in data on
* this socket.
*
* Valid for all sockets: SocketImpl, DatagramSocketImpl
*
* @see Socket#setReceiveBufferSize
* @see Socket#getReceiveBufferSize
* @see DatagramSocket#setReceiveBufferSize
* @see DatagramSocket#getReceiveBufferSize
*/
public final static int SO_RCVBUF = 0x1002;
我还是觉得与底层有关,因为setReceiveBuffer只是告诉JAVA系统设定一种缓冲机制
但数据总是要发送到网络上的。在物理层,存在一个最小发送长度,如通过ATM传送时好象是512个字节,你可以看看有关书籍,自然明白底层的运作
和物理层无关,任何应用层数据都会在IP层被分割层多个IP包,由TCP层负责传输和顺序、差错控制。难道各位做程序都只发512字节吗?
是这样,例如TCP层发送数据513个字节,但你的网卡与下一个节点如中继器的通信有一个最小发送单位--比方512个字节。当TCP层flush()时物理层即网卡发送了两个数据包:一个512个字节;另一个也是512个字节(但只包含一个有用数据。当从另一端接收时,第一次read将512个字节放入了你的缓冲区(注意:接收必须是以数据包为单位),所以你必须再read一次