一,引言TCP文件传输问题
我打开并从文件中读取,在读取时通过TCP套接字发送数据块。
发送方码
byte[] buffer = new byte[16384];
while ((in.read(buffer)) > 0)
{
SendProtocol(new FileTransfer(sender, receiver, buffer);
}
接收机CODE
if(o instanceOf FileTransfer)
FileTransfer tf = (FileTransfer) o;
out.write(tf.getData);
}
II。问题
我通过TCP套接字发送协议后,查看要发送的字节。他们都是独一无二的。但在接收端,收到的字节只是一个字节[]一遍又一遍。
三,示例
SENDER BYTES
[3, 3, 5, -44, 4, 3]
[99, -3, 5, -44, 7, 3]
[-11, 3, 5, -44, 4, 7]
[10, 6, 5, -44, 4, 66]
RECEIVER BYTES
[3, 3, 5, -44, 4, 3]
[3, 3, 5, -44, 4, 3]
[3, 3, 5, -44, 4, 3]
[3, 3, 5, -44, 4, 3]
什么是你'SendProtocol'和'FileTransfer'类?他们不是标准的Java库。 – 2010-11-22 04:30:35
SendProtocol是我的客户端网络类中的一个功能,它委托套接字的所有TCP连接等。循环监听输入和输出流的协议。我的FileTransfer类不是标准的Java库,它是一个包含发送者,接收者和字节的可序列化的类对象。 (有没有更好的方法来做到这一点O_O)? – user515574 2010-11-22 05:58:07