Network file transfer
Norman Maurer
norman.maurer at googlemail.com
Wed Oct 12 07:27:37 EDT 2011
Hi there,
the code I wrote here was not a full example.. it was just something
to show the idea. You will need to adjust it a bit.
Bye,
Norman
2011/10/11 metalstorm <metalheadstorm at gmail.com>:
> ok ive tried:
>
> 'ChanneBuffers.wrappedBuffers(byte[])'
>
> I get corrupted data on the client end.
>
> using a dynamic buffer
>
> private final ChannelBuffer buf = new DynamicChannelBuffer(1024 * 8);
>
> FileInputStream in = new FileInputStream(myFile);
>
>
> byte[] buffer = new byte[1024 * 8];
>
> int read = 0;
> int totalRead = 0;
> System.out.println("file size: " + myFile.length());
> while ((read = in.read(buffer, 0, buffer.length)) > 0)
> {
> buf.writeBytes(buffer, 0, read);
> // ch.write(ChannelBuffers.wrappedBuffer(buffer, 0, read));
> ch.write(buf);
> totalRead += read;
> System.out.println("read: " + read);
> System.out.println("totalread: " + totalRead);
>
> }
>
> which seems to give me double the file on client end, so if the file
> contained 1234 i would get 12341234
>
> im using Normans code with
> FileOutputStream out = new FileOutputStream("fileToSend.txt", true);
> I find it has to be set to true otherwise the file is only 1 buffer size big
>
> Sample debugging data:
>
> Server:
>
> got file: fileToSend.txt
> file size: 8206
> read: 8192
> totalread: 8192
> read: 14
> totalread: 8206
>
> Client (line.length):
>
> has array: 1024
> has array: 2048
> has array: 2048
> has array: 3072
> has array: 4096
> has array: 4124
>
> to save your maths, = 16412 = (8206 x 2)
>
> I don't see how it receiving 2x the data when on 1 x is sent?
>
>
>
>
>
> --
> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Network-file-transfer-tp6875434p6882322.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
More information about the netty-users
mailing list