I have a strange bug in my midlet. Each of the mobile phone must be client and server at the same time (via a Bluetooth connection). The problem is that sometimes (almost one out of ten tries), the server acts strangely. The server thread hangs on :
(this is normal) but when a client tries to connect with :
the server hangs for 5 seconds (the mobile phone is totally frozen for 5 seconds), then the client throws an IOException whose message is "Connection rejected". The server doesn't throw an exception, it still waits for a client to connect.
I have tried lots of things, but this problem still exists. As each mobile acts as a client and as a server at the same time, there could be the problem, but I have read a lot of Bluetooth documentation and I can't find where.
May someone point me in the right direction to debug this ? Any idea is welcome !
The answer is yes, the server runs in its own thread, as well as the client. To this point, my guess is that between the time the server was discovered thanks to the device / service discovery and the time the client tried to connect, something goes wrong on the server connection. What could cause this malfunction ? Is there some things that can not run at the same time on the same mobile ? (e.g. a device discovery on the client part of the application and the connection of a client on the server part) Thanks !
Just out of curiosity, how does it work through the Wireless Toolkit with their defualt emulator?
Mark
Thibault Revidon
Greenhorn
Joined: Aug 26, 2005
Posts: 6
posted
0
Nice move Mark ! it works fine in the Sun's WTK. I can't achieve why it doesn't in the Nokia emulator though !
Thibault Revidon
Greenhorn
Joined: Aug 26, 2005
Posts: 6
posted
0
Uh oh my mistake ... after some time I get the same IO Exception with the message "connection is refused". I thought the client which was running a service discovery in the background could prevent the server to work correctly, so I have tried to stop the server when a discovery was launched, but it produced no change. Also I made the cyclical discoveries occur after a random time on each phone, but it does not seem to improve.
Thibault Revidon
Greenhorn
Joined: Aug 26, 2005
Posts: 6
posted
0
Hello again !
Ok, I have cut my code to make it only 6 KB.
Finally, here is the problem : when I try to connect two clients to one server, both clients hang, and then I get the "connection rejected" error. It works with only one clients and several servers, so I guess my devices/services discovery is ok. I have tested how much clients my server can have (thanks to the LocalDevice.getProperty() method) : 7 on the Sun emulator, 5 on the Nokia emulator (Nokia 6230).
My guess is that the server send the same connection string to all clients until someone connects, so they try to connect to the same channel ! What I would like to know is what is the correct implementation of the run method of the server to make it accept several clients ?
Here is the code of the server's run() method :
My Server class implements the Runnable interface. The constructor starts a Thread which contains my Server object. Note : "running" (boolean) is always true in this example.
One thing to know is that you are creating a scatternet, and they can have one master and up to 7 clients/slaves. There is a way too extend that through multiple scatternets with one client acting as the master to the other scatternet and passing the other slaves communications in the other scatternet to this scatternet.