views:

65

answers:

3

Hi everyone, i am able to xfer files from 1 mobile device to another. When the sender sends this text file of 8 bytes, the receiver end will become a 256bytes txt file and when i open the contents of the txt file, there are my infos plus alot of square boxes. Here is my code from the sender:

            string fileName = @"SendTest.txt";
            System.Uri uri = new Uri("obex://" + selectedAddr + "/" + System.IO.Path.GetFileName(fileName)); 
            ObexWebRequest request = new ObexWebRequest(uri);

            Stream requestStream = request.GetRequestStream(); 
            FileStream fs = File.OpenRead(fileName);

            byte[] buffer = new byte[1024]; 
            int readBytes = 1;

            while (readBytes != 0) 
            {
            readBytes = fs.Read(buffer,0, buffer.Length);
            requestStream.Write(buffer,0, readBytes);
            }

            requestStream.Close();
            ObexWebResponse response = (ObexWebResponse)request.GetResponse();
            MessageBox.Show(response.StatusCode.ToString());
            response.Close();

Any1 knws how do i solve it?

+1  A: 

It seems 256 bytes is the minimum packet size in bluetooth session. Since your file size is smaller than 256 bytes the payload is filled in with some special character. Try to read the 256 byte array until EOF (^z) character and take bytes till EOF only and save to disk. You need to discard the payload.

this. __curious_geek
How do i discard the "payload?" ?
cheesebunz
btw, my codings are under button click event. (btnSend)
cheesebunz
read each byte in the array of 256 bytes until an EOF character. Save these bytes to your file and ignore remaining bytes in the array.
this. __curious_geek
Hmm, could you show me an slight example ? Pardon me but what's EOF character
cheesebunz
I'm maintainer of 32feet.NET and I don't think this answer makes sense. OBEX sends the payload alone and with no padding.
alanjmcf
Alan, how do i correct it? any ideas?
cheesebunz
A: 

Hey cheesebunz

So when you add some debugging to your code sample, adding a dump of readBytes after the Read call what do you see? 8 then 0 alone?

What language if your file in? A western language or something eastern for instance?

What are the contents of the file before and after? What bytes are being added and where?

alanjmcf
Pardon me but how do i add a dump ?Er, i'm using western language abcd.Scenario now,Sender with text file(25bytes) content:GeraldAndrewKsonDddd.Receiver of text file(256bytes) content with [] as weird characters:GeraldAndrewKsonDddd[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
cheesebunz
Well i tried an easier way. Not reading of any bytes: Uri uri = new Uri("obex://" + adr + "/" + System.IO.Path.GetFileName(fileName)); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(fileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close();The thing now is, how large of size i could send over? i tried a musicfile.mp3 10.2Mb, OutofMemoryexecption came out.My storage have 16 mb left, it should be enough...
cheesebunz
A: 

Anyways, i solved error using:

string fileName = @"SendTest.txt";

String adr = "0025677FB346";

Uri uri = new Uri("obex://" + adr + "/" + System.IO.Path.GetFileName(fileName));

ObexWebRequest request = new ObexWebRequest(uri);

request.ReadFile(fileName);

ObexWebResponse response = (ObexWebResponse)request.GetResponse();

MessageBox.Show(response.StatusCode.ToString());

response.Close();

cheesebunz