[ This chapter does not appear in the book. ]
Bluetooth is a wireless technology for communication over distances of up to 10m, offering reasonably fast data transfer rates of around 1 Mb/s, principally between battery-powered devices. Bluetooth's primary intent is to support the creation of ad-hoc personal area networks (PANs) for small data transfers (or voice communication) between devices such as phones and PDAs.
Bluetooth is ideal as the communications layer for mobile games involving a small number of players, such as sports (e.g. tennis) and networked board games (e.g. Go). An oft-cited drawback that the players must be physically near each other is actually perceived as an advantage by people who enjoy a social element in their gaming.
Bluetooth-based games offer a playing experience quite different from traditional networked gaming (e.g. MMORPGs) with their emphasis on size and interactions-at-a-distance. Those types of mobile games will most likely utilize 802.11b (WiFi) technology, acting as an extension to existing (non-wireless) networks, such as LANs.
Bluetooth PANs come in two main configurations: piconets and scatternets. A piconet is analogous to a client/server application, and is the focus of this chapter. Piconets are so named because they only permit a maximum of seven clients to be connected to a server at a time.
The principal aim of this chapter is to introduce J2ME's Bluetooth API (known as JSR 82) by explaining how to use it in a simple client/server application.
This chapter's example shows how a server 'registers' itself as a Bluetooth server, and processes client connections and messages. A client searches for Bluetooth devices and services, connects to a matching server, and sends messages to it. Several clients can be connected to the server at once, with the server using a dedicated thread for each one. Many of the Bluetooth-related classes developed here will be used in later chapters.
Once communication has been established, the application task is quite simple: a message sent by a client is echoed back by the server thread, changed to uppercase.
The screenshots on the right show the main client and server screens in the application. The client has just sent the message "hello", and received back "HELLO". The server shows the number of client handlers it is currently managing (only one), and displays a list of messages received from its clients.
The clients and server MIDlets were tested using Sun's WTK 2.2, with everything running on the same machine. The MIDlets use JSR 82's Bluetooth API, which is offered as an optional component in the WTK.
Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to my home page