×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    61

    Question Problem reading to InputStream

    Hello,

    I'm usign RFCOMM to transfer a file between 2 devices but I have a problem.

    first I pass a string from the server to the client and this works correct.
    Then I want to pass the a jpeg image (suppose I saved it into fileAsBytes) from the server to the client:

    //Server
    outputStream.write(fileAsBytes, 0, fileAsBytes.length);

    //Client
    OutputStream out = filestream.openOutputStream();
    while (inputStream.available()>0) {
    out.write(inputStream.read());
    System.out.print(".");
    }

    But the loop on the client is never executed: anyone can help me?

    I have tried to pass the file size from the sender to the receiver but the information that the client receive is not correct. Can anyone suggest a way to do this?

    Thank you in advance!

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    61

    Re: Problem reading to InputStream

    I generalize the problem:

    I have to transfer from a server to a client: string1, image1, string2, image2:

    //Server
    outputStream.write(string1)
    outputStream.write(image1)
    outputStream.write(string2)
    outputStream.write(image2)

    //Client
    inputStream.read(string1)
    inputStream.read(image1)
    inputStream.read(string2)
    inputStream.read(image2)

    This is only "pseudo-coude". On the use a loop to read the data from the server. All go weel until the loop for receiving image2, that is never executed. I have tried in several ways, but there is no mean.

    Can somebody help me?

    Thx a lot!

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Italy
    Posts
    15

    Re: Problem reading to InputStream

    Quote Originally Posted by Mich2424
    But the loop on the client is never executed: anyone can help me?
    I suggest you to try to read data with the following function (you must know how many bytes you have to read):

    Code:
    private void readData(InputStream inputStream, byte[] buffer, int bytesToRead)
        	throws IOException
        {
            int bytesRead = 0;
            
            while (bytesRead < bytesToRead)
            {
            	int count = inputStream.read(buffer, bytesRead, bytesToRead - bytesRead);
                
                if (count == -1)
                {
                    throw new IOException("Input stream closed");
                }
                
                bytesRead += count;
            }
        }
    Quote Originally Posted by Mich2424
    I have tried to pass the file size from the sender to the receiver but the information that the client receive is not correct. Can anyone suggest a way to do this?
    Are you sure that you correctly send the size number? How do you read it in the client?


    Marco Pracucci

Similar Threads

  1. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  2. Replies: 4
    Last Post: 2005-12-19, 15:59
  3. problem in reading sms index
    By hosam2010 in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2005-06-12, 17:39
  4. Problem with reading phone book details in noka 6210
    By master131181 in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2004-05-02, 14:54
  5. Problem reading a data file
    By xcoutin in forum Symbian
    Replies: 2
    Last Post: 2003-08-20, 17:54

Posting Permissions

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