×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    12

    Sending file via GPRS

    Hi everybody,

    i have a problem while sending a file of 11 kb size (size on the phone) from my Nokia 6680 to a my pc (server).
    I receive on the server side a file of 8 kb, impossible to read of course and in which i have the first 1024 bytes (not equal to zero) and the rest of the bytes is equal to zero.

    i think that the (FileConnection)Connector.open read the first 1024 of the file in the memory ... IS THAT TRUE ??

    why i suppose that ?

    because when i use the VIEW FILE option in my Midlet (which is the same as on the PDAPDemo on the wireless toolkit), it open a text file in which i have just few bytes written on 1 line ... so it can't be the whole file !!!!


    Here is my code ....... PLEASE HELP ME ....

    Best regards




    private void send(String fileName) {

    int length = 0;


    // Connection to file
    try {
    fc = (FileConnection)Connector.open("file://localhost/" + currDirName + fileName);
    if (!fc.exists()) {
    throw new IOException("File does not exists");
    }

    fis = fc.openInputStream();

    // Connection to server
    sc = (SocketConnection) Connector.open("socket://MY IP:5000");



    is = sc.openInputStream();
    os = sc.openOutputStream();


    byte[] b = new byte[1024];



    do {
    length = fis.read(b, 0, 1024);
    os.write(b);
    } while (length >= 1024);


    fis.close();
    fc.close();
    stop();
    } catch(IOException e) {}
    }

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: Sending file via GPRS

    Code:
    do {
    length = fis.read(b, 0, 1024);
    os.write(b);
    } while (length >= 1024);
    That's your problem. If you check the documentation for InputStream.read(byte[], int, int) you'll notice it says:
    An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero.
    So you shouldn't assume length will be 1024 as long as there is data avaiable. If we again look at the documentation for that method we'll see:
    Returns:
    the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
    So what you need to do is change the last line of that segment to:
    Code:
    } while (length != -1);
    shmoove

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    12

    Re: Sending file via GPRS

    many thanks for your fast reply,

    i tried and it didn't work .. i received the same file on the server with the first 1024 bytes

    i think that my problem is that my MIDLET can't read the whole file ... maybe the first 1024 bytes only ....

    what can i do so it can read the whole file and then i can be able to send the whole file to the server ??

    hint: is there a way to view a image (for example) inside the midlet PDAPDemo of the wireless toolkit ? :-)

    Maybe this may help me ... but i am not sure ...

    Kind regards,

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    12

    Re: Sending file via GPRS

    thanks a lot for your help I found the bug ..

    when i send a text file it works ... but with an image it wasn't
    which is normal because i have to use ImageIO.Read to create a buffered image and then I can write it in a file ...

    Best Regards,

    Minou

Similar Threads

  1. File corrupted - with signed sis
    By annehj in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2007-12-10, 13:44
  2. could not find thread.mbg and thread.rsg
    By deercrane in forum Symbian
    Replies: 3
    Last Post: 2006-04-18, 09:44
  3. Sending XML file from server to mobile
    By bvsbh in forum Mobile Java General
    Replies: 1
    Last Post: 2005-11-30, 14:21
  4. strange behavior on sending jar file via WAP for different mobile network
    By thone in forum Digital Rights Management & Content Downloading
    Replies: 2
    Last Post: 2005-10-28, 07:53
  5. sending header info for .3gp file fails
    By stoem in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2004-03-01, 09:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×