×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    10

    Problems with Receiving Data over bluetooth

    Hello Everyone,

    I have created a File sharing application over Bluetooth RFCOMM. The application works in that the file is transmitted over over the connection through the DataOutputStream. I have written the application so that on one side a FileConnector is opened and an InputStream is used to read in the file in bytes and a DataOutputStream is used to write out the data. On the receiver side a DataInputStream is used to read in the bytes from the connection and a FileConnector OutputStream is used to write the bytes out.

    I have implemented some code so that the file is broken up into 1024Byte chunks and sent across the connection. The file is sucessfully received, however, if the file is large then the data seems jumbled. For example if I send across a jpg file then the result is a jpg that contains some of the picture but not all of it.

    Does anyone know why might be happening?

    I should say that this application runs on a mobile device using J2ME but this should make any difference. In simulation this works fine, but I have come to realise that simulation for Bluetooth is almost useless beyond testing the very basics of functionality.

    Here is the code that I use to read in the File from the sending phones memory, break up the File and Send it over in Chunks....I then use the same code on the receiver side to read in the File in chunks and write it out to the receiving Phones memory:

    Code:
    public void sendInChunks(DataInputStream input, DataOutputStream output, int togo) throws IOException 
    {
    			
    // copy bytes from input to output in chunksize-sized chunks
    int chunksize = 256;
    int totalsize = togo;
    byte bytes[] = new byte[chunksize];
    int writecount;
    int counter = 0;
    
    while (togo > 0) {
    				
                       writecount = (togo >= chunksize ? chunksize : togo);
    	           input.read(bytes, 0, writecount);
    	            
                         //Just a GUI progress element
    	            if(iamthereceiver == 1)
    	            {
    	            	counter = counter + writecount;
    	            	String sofar = new Integer(counter/1024).toString();
    	            	String total = new Integer(totalsize/1024).toString();
    	            	tf.setString(sofar + "/" + total);	      
    	            	//System.out.println("Download: " + counter);
    	            	g.setValue(counter);
    	            	
    	            }
    	            
    	           output.write(bytes, 0,  writecount);
    			    
    	           if(iamthereceiver == 1)
    		    {}
    		    
                        //added this to ensure the sender is always 20ms slower than the receiver	    
    	            else
    		     {
    			    	try{
    		            Thread.sleep(20);
    				    }catch(InterruptedException ie){}
    		     }
    			    
    		     togo = togo - writecount;
    	      }
    			
         output.flush();
    
    }
    Last edited by gjmcnamara; 2008-05-01 at 17:35. Reason: updates

Similar Threads

  1. problem in transfer data with Bluetooth in real devices
    By tortoisevn in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-11-07, 11:35
  2. How to transfer data using bluetooth?
    By venaktareddy in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-06-06, 13:22
  3. Receiving RTP data on TCP channel
    By girish_1978 in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 1
    Last Post: 2006-05-18, 06:32
  4. 6230 global problems with Bluetooth
    By asterixmlm in forum General Development Questions
    Replies: 1
    Last Post: 2004-12-10, 17:12
  5. Receiving a Data call on Nokia 6310i
    By aledain in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2003-12-18, 00:28

Posting Permissions

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