Network file transfer

Norman Maurer norman.maurer at googlemail.com
Tue Oct 11 01:55:43 EDT 2011


Hi there,

what you just listed here is how you would do it with blocking IO.
This will not work in the NIO world. Keep in mind that netty is an
event driven network framework. You MUST take care that you NEVER (or
at least kind of) block the IO-Worker-Thread.

In netty you get the data "pushed". So you don't pull like you would
do with InputStream.read(..), as this would block the IO-Worker-Thread
and so make the whole server unresponsible.
So in netty you usual have a ChannelPipeLine which contains the
following stuff for incomming traffic:

* framer:
  This is the piece of code that will "dispatch" a ChannelBuffer to
the rest of the pipeline once it is ready. This could for example
because of a CRLF or something else.

* decoder (you may not need one if you want to work with the "raw"
ChannelBuffer):
  Decode the ChannelBuffer to something more meaningful for you

* coreHandler:
  Some class which extends SimpleChannelUpstreamHandler and does the
businesslogic.

Be aware that if your coreHandler does kind of blocking stuff (which
could be any kind of things like writing to the fs, dns query, db
actions) you will need to add an ExecutionHandler in front of it. This
will take care of "offloading" the tasks to another ThreadPool and so
keep the IO-Worker-Thread free.

This javadoc gives a good overview about the "event" flow:
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/ChannelPipeline.html

Bye,
Norman


2011/10/10 metalstorm <metalheadstorm at gmail.com>:
> The c# app sends a file name, size etc to the client which is then followed
> by the file (data)
>
> Its a P2P app, i cant remember the proper name, but each application has
> both a client and server running. Servers send files to clients and *not*
> vice versa.
>
> The Http stuff like, "
> http://localhost:8080/?file=c:/myfiles/myfilepath.txt" is unneeded from what
> i can tell, and from what i see in my head, all the file related data is
> held in a custom packet object and serialized/deserialized before actual is
> sent.
>
> So there's no build in file handling stuff (client side) in netty for file
> transfers ? So clients would have something like:
>
>
>                InputStream in = sock.getInputStream();
>                FileOutputStream out = new FileOutputStream("received.txt");
>
>                int bytes = 0;
>                byte[] buffer = new byte[8192];
>                int len;
>
>
>                while ((len = in.read(buffer)) > 0)
>                {
>                        out.write(buffer, 0, len);
>                        bytes += len;
>                }
>
>                out.close();
>                sock.close();
>
> Sorry to be a pain with all the questions, but im trying to get this right
> :)
>
> thanks again.
>
> --
> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Network-file-transfer-tp6875434p6878549.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