• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Bluetooth] Client and server at the same time?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

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 !

Thank you very much !

Thibault
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well first I would ask, do you have the Server running in a seperate thread? It should be in its own thread.

Mark
 
Thibault Revidon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mark and thank you for your reply.

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 !
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nah, that shouldn't be a problem. Maybe the device went out of range between the discovery time and the start of the Connection. Just a guess.

Mark
 
Thibault Revidon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is that it acts like this on the nokia emulator ...

I haven't tried it on real device yet, but it would probably do the same ...
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just out of curiosity, how does it work through the Wireless Toolkit with their defualt emulator?

Mark
 
Thibault Revidon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

What is wrong with this implementation ?
Thanks !

Thibault
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic