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