Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cf-dev] transfer of large files

Hello Julien!

 

Thank you for your reply.

 

The problem occurred always when I tried to transfer the large file of 130MB.

Currently, I do not have a unit test for that, but in order to reproduce this behavior just follow these steps:

1) add a new resource within the HelloWorldServer.java:

 

add(new HelloWorldResource(), new FileResource("fileResource", "file.dat"));

 

2) For the needed FileResource.java use:

 

import java.nio.file.FileSystems;

import java.nio.file.Files;

import java.nio.file.Path;

import org.codehaus.plexus.util.StringUtils;

 

public class FileResource extends CoapResource

{

                private String fileName = "file.dat";

 

                public FileResource(String resourceName, String fileName)

                {

                               // set resource identifier

                               super(resourceName);

 

                               this.fileName = fileName;

 

                               // set display name

                               getAttributes().setTitle("File Resource");

                }

 

                @Override

                public void handleGET(CoapExchange exchange)

                {

 

                               // respond to the request

                               Path p = FileSystems.getDefault().getPath("C:\\path\\to", fileName);

                               byte[] fileData = null;

                               try

                               {

                                               fileData = Files.readAllBytes(p);

                               }

                               catch (IOException e)

                               {

                                               System.out.println(StringUtils.join(e.getStackTrace(), "\n"));

                                               return;

                               }

 

                               String string = null;

                               try

                               {

                                               string = new String(fileData, "UTF-8");

                               }

                               catch (UnsupportedEncodingException e)

                               {

                                               System.out.println(StringUtils.join(e.getStackTrace(), "\n"));

                                               return;

                               }

 

                               System.out.println("Sending to client.");

                               // exchange.respond(string);

                               exchange.respond(ResponseCode.CONTENT, fileData);

                }

}

 

3) The file “file.dat“ is some large text document that I simply created with an editor using copy&paste exponentially J

4) Start the HelloWorldServer

5) Start the GETClient with the argument: “coap://localhost/fileResource”

 

Greetings,

Helge

 

Von: cf-dev-bounces@xxxxxxxxxxx [mailto:cf-dev-bounces@xxxxxxxxxxx] Im Auftrag von Julien Vermillard
Gesendet: Mittwoch, 10. Dezember 2014 13:35
An: Californium (Cf) developer discussions
Betreff: Re: [cf-dev] transfer of large files

 

Wow 130MB is a lot for CoAP, I wonder if it was ever tested..

It's failing 100% of time? Can you provide detailed debug logs or a JUnit test so we can try to reproduce it?

Julien

_______________________________________________
cf-dev mailing list
cf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cf-dev


Back to the top