Reconnect to a device using bluetooth doesn't work

Hi all,

i have written a simple program where two devices connect using bluetooth, everything works fine at the end one of the devices decide to end the communication, so both devices exit the program without any problem.

now if i try to run the program again (without closing the emulator) the server runs and waits for a connection, the client runs and calls the Connector.open() no exceptions are raised (in both sides) but at the same time no connection is established.

i thought that this has soemthing to do with releasing resources.. so i set the streams and vecotrs to null hoping that this would take care of the problem but it didn't work. i have some static constants but i doupt that they have such a bad influence.

i am running out of ideas, if no exceptions are raised then why is it not establishing the connection?

appreciate your help.

[891 byte] By [malrawia] at [2007-11-27 4:57:59]
# 1

ok i know the cause but i don't know how to correct it.

see the client and server both run a loop in a thread to read from each other.

the server runs a while loop to get a message from the client, inside the while loop it is blocked because of the read(). so even when the client exits and calls the close() of the InputStream and OutputStream the server still waits for an input from the client.

i expected the read() to return -1 because the client closed the streams but that's not the case.

is there any way to unblock the server?

how can i make communication between the client and server in a better way ?

thanks in advanced

malrawia at 2007-7-12 10:13:45 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

OKay, i got rid of the blocking caused by the read() by using available() before trying to read.

the threads are ending variables set to null, everything looks good in theory, YET when i run the program again the client doesn't seem to connect to the server using Connector.open().. again no exceptions raised nor connection established.

suggestions PLease

malrawia at 2007-7-12 10:13:45 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Please help, this is strange thing i mean not being able to run the program more than once.
malrawia at 2007-7-12 10:13:45 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
Ok i figured it out at last... here is the answer for those who might get stuck with the same situation:i had to close the StreamConnectionNotifier before ending the program to remove the service record from the DB by calling the close():notifier.close();
malrawia at 2007-7-12 10:13:45 > top of Java-index,Java Mobility Forums,Java ME Technologies...