可靠地写入Java SocketChannel

joh*_*ker 2 java sockets socketchannel

我有一个关于java SocketChannel的问题.

假设我在阻塞模式下打开了套接字通道; 在调用write(ByteBuffer)方法之后,我得到一个描述写入了多少字节的整数.javadoc说: "返回:写入的字节数,可能为零"

但究竟什么意思呢?这是否意味着真正传递给客户端的字节数(以便发送方收到tcp ack表明服务器已接收到多少字节),或者这是否意味着已将字节数写入tcp堆栈?(这样一些字节仍然可能正在等待,例如在网卡缓冲区中).

Ste*_*n C 5

does this mean that the number of bytes really has been delivered to the client

No. It simply means the number of bytes delivered to the local network stack.

确保数据已传送到远程应用程序的唯一方法是,您收到数据的应用程序级别确认.