Thanks for help !
That's me again, I have another problem playing with the bluetooth and linux
This time, I had wrote a small program run at linux, which sends a file to a bluetooth device via OBEX. However, it works for smaller size files. For those a bit larger files, it fails (connection closed during the sending process). And I have tried to send the same file by obexpush and obex_test, it works. The file used for testing is about 3M
Here is my program code :
showMessage("Connecting to Client .. ", true);
ClientSession conn = (ClientSession) Connector.open(targetServiceURL);
HeaderSet response = conn.connect(null);
int status = response.getResponseCode();
if(status != ResponseCodes.OBEX_HTTP_OK)
{
showMessage("OBEX connection error!!", false);
conn.close();
}
else
{
showMessage("Connected.", false);
showMessage("Reading Input File .. ", true);
InputStream is = (InputStream) (new FileInputStream(objectName));
int objectLength = is.available();
String type = getObjectType(objectName);
HeaderSet head = conn.createHeaderSet();
head.setHeader(HeaderSet.COUNT, new Long(1));
head.setHeader(HeaderSet.TYPE, type);
head.setHeader(HeaderSet.NAME, objectName);
head.setHeader(HeaderSet.LENGTH, new Long (objectLength));
showMessage( objectLength + " bytes Read. ", false);
showMessage("Opening OutputStream .. ", true);
Operation op = conn.put(head);
OutputStream os = op.openOutputStream();
showMessage("Opened.", false);
showMessage("Sending .. ", true);
// send the file to the client
int position = 0, n = 0;
while (position < objectLength)
{
int sendLength = ((objectLength - position > 1024) ? 1024: objectLength - position);
byte[] data = new byte[sendLength];
is.read(data);
showMessage("sendLength = " + sendLength + ", Position = " + position + ", File Size = " + objectLength + ". ", false);
os.write(data);
os.flush();
position += sendLength;
} */
showMessage("Closing Connection .. ", true);
is.close();
os.close();
op.close();
conn.disconnect(null);
conn.close();
showMessage("Closed. ", false);
showMessage("Bye bye !", true);
Would anyone has ideas ? Thanks very much !