public class L2capServer extends EchoParticipant
implements Runnable {
L2capMtuMIDlet parent;
private String url;
public L2capServer(L2capMtuMIDlet parent) {
this.parent = parent;
this.out = parent.displayField;
}
public void start(String url) {
this.url = url;
new Thread(this).start();
}
public void run() {
LocalDevice device = null;
L2CAPConnectionNotifier notifier = null;
try {
device = LocalDevice.getLocalDevice();
/* Request that the device be made discoverable */
device.setDiscoverable(DiscoveryAgent.GIAC);
} catch(BluetoothStateException e) {
234 Chapter Eight: L2CAP
parent.displayError("Error",
"BluetoothStateException: " +
e.toString());
return;
}
try {
notifier = (L2CAPConnectionNotifier)
Connector.open(url);
} catch (IllegalArgumentException e) {
parent.displayError("Error",
"IllegalArgumentException in" +
"Connector.open()");
} catch (IOException e) {
parent.displayError("Error",
"IOException: " +
e.getMessage());
}
if (notifier == null) {
return;
}
try {
out.setLabel("["+url+"]");
for (;;) {
L2CAPConnection conn = notifier.acceptAndOpen();
echoReceivedL2capPackets(conn);
conn.close();
}
} catch(IOException e) {
parent.displayError("Error",
"IOException: " +
e.getMessage());
} catch (IllegalArgumentException e) {
parent.displayError("Error",
"IllegalArgumentException: " +
e.
Pages:
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293