I think this code is working only on localhost, becuase you send the
serialized File object and not the content of file. The serialized File
object contain the path of file, so the length is correct. You must write
the content of file to IoSession. You can use FileChannel to load files to
ByteBuffer (the code is an example only, I don't tested this):

*            File file = new File("any file name");
>             FileInputStream fis = new FileInputStream(file);
>             FileChannel channel = fis.getChannel();
>             long readed = 0;
>             while(readed != file.length()){
>                 ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0,
> 1024);
>                 buffer.rewind();
>                 readed += buffer.limit();
>                 session.write(buffer);
>             }    *
>


2008/6/27 kalees waran <[EMAIL PROTECTED]>:

> On Fri, Jun 27, 2008 at 1:41 PM, Viktor Balázs <[EMAIL PROTECTED]>
> wrote:
>
> > Do you want to write byte content of file or a "new File(...)" object? :)
> > Or
> > what is the "file object"? Do you send an example?
> >
> > 2008/6/27 kalees waran <[EMAIL PROTECTED]>:
> >
> > > i want to send and download bulk file using mina. i am trying to write
> > file
> > > object in the session.write(fileobject).however i got client side in
> null
> > > pointer exception..which codec i want to use to write object in mina
> > >
> >
> public class Client {
>  public static void main(String arg[]){
>
>    SocketConnector connector = new SocketConnector();
>    connector.setWorkerTimeout(1);
>    SocketConnectorConfig cfg = new SocketConnectorConfig();
>    cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
>    cfg.getFilterChain().addLast( "codec",new ProtocolCodecFilter( new
> ObjectSerializationEncoder(),new ObjectSerializationDecoder() ));
>    cfg.getFilterChain().addLast("threadPool", new
> ExecutorFilter(Executors.newCachedThreadPool()));
>    IoSession session;
>    ConnectFuture future = connector.connect(new InetSocketAddress("
> 192.168.10.197", 9123),
>        new ClientHandler(), cfg);
>        future.join();
>
>            session = future.getSession();
>
>            session.getCloseFuture().join();
>
> session.close();
>
>
> }
>
> > //handler
> >
> public void sessionCreated(IoSession session) throws Exception{
>
>        File f=new File("E:/Downloads/voicesys.exe");
>        System.out.println(f.length());
>        session.write(f);
>        session.write("ksdkosfsd");
>
>
>    }
>
> ////////////////////server
>
> public void messageReceived(IoSession session, Object msg) throws Exception
> {
>
>        Object o=msg;
>        File f=(File)o;
>        System.out.println(f.length());
>        System.out.println(msg);
>        session.write("hi");
>        session.close();
>    }
>
> i have write this code for sending and receiving file
> now its working fine...i want to know this is the  right coding to send the
> file to server bz my work is more challaging work.bz there is the chance
> 20000 client to sent and download file at a time..even i dont have any
> clear
> idea about thread pooling in mina.i wnt to send to voice file the size may
> big...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> >
> >
> >
> > --
> > Balázs Viktor
> > Amkai Kft. (1188 Budapest, Szövet u. 9.)
> >
> > Email: [EMAIL PROTECTED]
> > Jabber: [EMAIL PROTECTED]
> > MSN: [EMAIL PROTECTED]
> > Telefon: +36-30/6755532
> >
>



-- 
Balázs Viktor
Amkai Kft. (1188 Budapest, Szövet u. 9.)

Email: [EMAIL PROTECTED]
Jabber: [EMAIL PROTECTED]
MSN: [EMAIL PROTECTED]
Telefon: +36-30/6755532

Reply via email to