想实现最简单的文件传输,自己传给自己2G的文件也没什么问题。但是在局域网里传输就丢包严重,几k的文件都不能传好大致代码如下发送方:skt=newSocket(ip,port);printStream=newPrint...
想实现最简单的文件传输,自己传给自己2G的文件也没什么问题。但是在局域网里传输就丢包严重,几k的文件都不能传好
大致代码如下
发送方:
skt = new Socket(ip, port);
printStream = new PrintStream(skt.getOutputStream());
while( (readCount = fileReader.read(buffer, 0, 65535)) != -1 )
printStream.write(buffer, 0, readCount);
接收方:
fileReader = new BufferedInputStream(clientSkt.getInputStream());
fileWrtier = new BufferedOutputStream( new FileOutputStream(path) );
while( (readCount = fileReader.read(buffer, 0, 65535)) != -1 )
fileWriter.write(buffer, 0, readCount);
skt = new Socket(ip, port);
printStream = new PrintStream(skt.getOutputStream());
while( (readCount = fileReader.read(buffer, 0, 65535)) != -1 )
printStream.write(buffer, 0, readCount);
接收方:
fileReader = new BufferedInputStream(clientSkt.getInputStream());
fileWrtier = new BufferedOutputStream( new FileOutputStream(path) );
while( (readCount = fileReader.read(buffer, 0, 65535)) != -1 )
fileWriter.write(buffer, 0, readCount);
不知道问题出在哪里,或者有什么更好的解决方法呢?
谢谢
展开