How to Cancel sending via obex?

33 views
Skip to first unread message

Orlando José

unread,
Aug 15, 2011, 10:26:51 AM8/15/11
to bluecove-developers

I am developing an application to automatically send images.

How do I cancel sending the image, if people take too long to accept
the image?

Mina Shokry

unread,
Aug 15, 2011, 10:39:32 AM8/15/11
to bluecove-...@googlegroups.com
close the connection.

2011/8/15 Orlando José <orlan...@gmail.com>

I am developing an application to automatically send images.

How do I cancel sending the image, if people take too long to accept
the image?

--
You received this message because you are subscribed to the Google
Groups "bluecove-developers" group.
For more options, visit this group at
http://groups.google.com/group/bluecove-developers

Orlando José

unread,
Aug 15, 2011, 1:21:13 PM8/15/11
to bluecove-developers
OK thank's.

I have this method.

public boolean obexPut(String serverURL, String address) {
try {

System.out.println("Connecting ...");
c =
Connector.open(serverURL);
clientSession = (ClientSession) c;
RemoteDevice r = new RemoteDeviceExt(address);

hsConnectReply =
clientSession.connect(clientSession.createHeaderSet());
if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK)
{
System.out.println("Connect Error " +
hsConnectReply.getResponseCode());
}

hsOperation = clientSession.createHeaderSet();
hsOperation.setHeader(HeaderSet.NAME, fileName);
String type = "jpg";
if (type != null) {
hsOperation.setHeader(HeaderSet.TYPE, type);
}
hsOperation.setHeader(HeaderSet.LENGTH, new Long(data.length));

Operation po =
clientSession.put(hsOperation);

OutputStream os = po.openOutputStream();

ByteArrayInputStream is = new ByteArrayInputStream(data);
byte[] buffer = new byte[0x400];
int i = is.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i =
is.read(buffer);
}
os.flush();
os.close();
po.close();

HeaderSet hsDisconnect = clientSession.disconnect(hsOperation);

if (hsDisconnect.getResponseCode() == ResponseCodes.OBEX_HTTP_OK) {
progress.transferComplete("Success");
return true;
} else {
progress.transferComplete("Code " +
hsDisconnect.getResponseCode());
return false;
}


} catch (IOException e) {
Logger.error(e);
System.out.println("Communication error " +
e.getMessage());
return false;
} catch (Throwable e) {
Logger.error(e);
System.out.println("Error " + e.getMessage());
return false;
} finally {
if (clientSession != null) {
try {
clientSession.close();
} catch (IOException ignore) {
}
}
clientSession = null;

}
}


I am using Thread in the method main.

private void bluetoothDiscovery() {

Thread t = new Thread() {
public void run() {

while (true) {
//other methods
if(time > limitTime){
clientSession.close();
}


}
}
};
t.start();
}

How do I close the connection when the application is waiting for
confimação user?
















On Aug 15, 11:39 am, Mina Shokry <minasho...@gmail.com> wrote:
> close the connection.
>
> 2011/8/15 Orlando José <orlando...@gmail.com>

Mina Shokry

unread,
Aug 15, 2011, 5:37:20 PM8/15/11
to bluecove-...@googlegroups.com
Please, always post a specific problem and if you'd post code, use minimum code snippets.

Almost no one have time to read and debug others' code.

2011/8/15 Orlando José <orlan...@gmail.com>

Orlando José

unread,
Aug 16, 2011, 8:07:22 AM8/16/11
to bluecove-developers
I'm sorry.

I'll be more specific.

I have the main method with a thread, it looks the devices available
and in another class is done sending the files via OBEX.

The connection to send is:
........
Connection connection =
Connector.open(serverURL);
ClientSession clientSession = (ClientSession) connection ;
HeaderSet hsConnectReply =
clientSession.connect(clientSession.createHeaderSet());
........


Now, for example: after 10 seconds, if the user don't accept the file,
i want to close the connection.

I already tried:
connection.close();
clientSession.close();


Thank's.








On Aug 15, 6:37 pm, Mina Shokry <minasho...@gmail.com> wrote:
> Please, always post a specific problem and if you'd post code, use minimum
> code snippets.
>
> Almost no one have time to read and debug others' code.
>
> 2011/8/15 Orlando José <orlando...@gmail.com>

Mina Shokry

unread,
Aug 16, 2011, 10:37:57 AM8/16/11
to bluecove-...@googlegroups.com
Well, I am not sure if what are you trying to do is possible. Review bluecove parameters for your stack and search for timeout.

2011/8/16 Orlando José <orlan...@gmail.com>
Reply all
Reply to author
Forward
0 new messages