且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送和接收的套接字文件

更新时间:2021-10-25 07:57:59

您需要:

  1. 发送文件的长度超前的文件。您可以使用 DataOutputStream.writeLong()是什么,以及 DataInputStream.readLong()在接收器。李>
  2. 在接收从流中读取正是很多字节:

  1. Send the length of the file ahead of the file. You can use DataOutputStream.writeLong() for that, and DataInputStream.readLong() at the receiver.
  2. Read exactly that many bytes from the stream at the receiver:

while (total < length && (count = in.read(buffer, 0, length-total > buffer.length ? buffer.length : (int)(length-total))) > 0)
{
    out.write(buffer, 0, count);
    total += count;
}

E&放大器; OE

E&OE

其实我想重置套接字连接

Actually I want to reset socket connection

其实你不想做任何这样的事情。

Actually you don't want to do any such thing.