Send large file

1,377 views
Skip to first unread message

MiltondSilva

unread,
May 18, 2010, 2:07:16 PM5/18/10
to kryonet-users
Hi,
could you provide an example of how to send/receive a large(10mb)
java.io.File?

I don't understand how to use the serialization at all. I register(on
both the client and server) the class java.io.File but, it gives me a
deserialization error.
I tried to send the entire file as an array of strings and it solved
that problem but then, it gave me buffer overflows I then switched the
params in the constructor of both the server and client to something
that could acomudate de entire file but I got buffer underflows.

Nate

unread,
May 28, 2010, 5:16:25 PM5/28/10
to kryonet-users
Hi,

KryoNet is for sending objects. A java.io.File object is only a
descriptor
of a file on your filesystem -- it is really just a wrapper around a
String
that is the path to the file. If you sent a java.io.File, the actual
file
contents would not be sent and the path would not be valid on the
receiving
side.

You could load your 10MB file into an object. An easy choice would be
a
large byte array. You could then send this byte array object using
KryoNet.
Note you will need buffers large enough to hold the entire file on
both
sides. Also with this approach, you won't be able to send other
objects
until the 10MB transfer is complete because the entire 10MB is queued
by
KryoNet for transfer up front.

You could create an object that contains only a portion of your file.
Eg,
this might be some identifier and a small byte array (say, 1024
bytes). You
would read from the file, populate this object with a portion of the
file,
send it, and repeat. The receiving side would receive these objects
and know
how to append the bytes to a file on the receiving side. Maybe the
identifier would tell it what file the bytes belong to, so you could
perform
multiple transfers concurrently. You may want a mechanism to avoid
queuing
all the smaller objects all at once. Queue a few, and only queue more
when
you know that the first were received. You could know this by having
the
receiving side send back an object indicating, "OK, I'm ready for more
bytes
for file X". By not queuing all the data up front, you won't need huge
buffers and you could still send other objects during your transfer.

This may be useful functionality to have built-in to KryoNet. I will
keep it
in mind next time I have a chance to work on the project.

-Nate

Nate

unread,
Aug 6, 2012, 10:51:42 AM8/6/12
to kryone...@googlegroups.com
Hi Jagoliveira,

Take a look at InputStreamSenderTest:
https://code.google.com/p/kryonet/source/browse/trunk/kryonet/test/com/esotericsoftware/kryonet/InputStreamSenderTest.java

-Nate


On Mon, Aug 6, 2012 at 7:49 AM, jagoliveira <jo...@gabrieldeoliveira.com.br> wrote:
Dear Nate,

It seems that you have implemented this functionality on KryoNet 2.
In affirmative case, can you post some example of it?

Thanks
Jagoliveira
--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users

Reply all
Reply to author
Forward
Message has been deleted
0 new messages