*/
public void commandAction(Command c, Displayable d) {
notifyDestroyed();
}
}
The next step is to write the HelloServer code. The run() method of
HelloServer does all the work. It makes the server device discoverable
so that the client can ?¬?nd the server. Next, the run() method waits for a
client to connect and reads all the data sent from the client. The run()
method displays the data sent from the client on the screen.
package com.jabwt.book;
import java.lang.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.bluetooth.*;
public class HelloServer extends BluetoothMIDlet {
/**
* Creates a server object. Accepts a single
* connection from a client and prints the data
* sent from the client to the screen.
*/
public void run() {
// Create a Form and add the Exit command to the Form
Form f = new Form("Server");
f.addCommand(new Command("Exit", Command.EXIT, 1));
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
Simple JABWT Application 47
try {
// Make the local device discoverable for the
// client to locate
LocalDevice local = LocalDevice.getLocalDevice();
if (!local.setDiscoverable(DiscoveryAgent.GIAC)) {
f.append("Failed to change to the " +
"discoverable mode");
return;
}
// Create a server connection object to accept
// a connection from a client
StreamConnectionNotifier notifier =
(StreamConnectionNotifier)
Connector.
Pages:
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90