Hi all.
I have a problem sending a message in my program. I am able to receive a message, but not so send it. when I try to send a message I get the following error:
Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.
java.io.IOException: Can't connect
at com.sun.kvem.jsr082.impl.bluetooth.BluetoothController.getBTSPPNotifierPort(BluetoothController.java:526)
at com.sun.midp.io.j2me.btspp.BTSPPConnection.clientConnectionGetTransportPort(BTSPPConnection.java:40)
at com.sun.kvem.jsr082.impl.bluetooth.BluetoothProtocolBase.processClientConnection(+103)
at com.sun.kvem.jsr082.impl.bluetooth.BluetoothProtocolBase.openPrim(+218)
at com.sun.kvem.jsr082.impl.bluetooth.BluetoothProtocolBase.openPrim(+10)
at javax.microedition.io.Connector.openPrim(+299)
at javax.microedition.io.Connector.open(Connector.java:222)
at javax.microedition.io.Connector.open(Connector.java:198)
at javax.microedition.io.Connector.open(Connector.java:180)
at forfra2.startmidlet.send_message(startmidlet.java:1095)
at forfra2.startmidlet.commandAction(startmidlet.java:259)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java:670)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
The relevant code (i think) is this:
void start_spp(){
System.out.println("Index = " + service_index);
current_service = (Service) services.elementAt(service_index);
senders_name_string_field.setText(current_service.getName());
senders_message_string_field.setText("No messages yet");
current_address = current_service.getURL();
System.out.println("Current address = " + current_address);
}
private void setupConnections() {
server = new Server(this);
server.start();
finder = new MyFinder(this);
finder.start();
}
public void serviceRemoved(Service bcs, int i) {
service_choicegroup.delete(i);
}
public void serviceAdded(Service bcs) {
String s = bcs.getName() + ":" + bcs.getAddress();
service_choicegroup.append(s, null);
}
private void send_message() throws IOException {
StreamConnection sc = null;
DataOutputStream dataOut = null;
try {
sc = (StreamConnection)Connector.open(current_address);
dataOut = new DataOutputStream(sc.openOutputStream());
LocalDevice bt = LocalDevice.getLocalDevice();
String from = bt.getFriendlyName() + ":" +bt.getBluetoothAddress();
dataOut.writeUTF(from);
dataOut.writeUTF(message_to_send_text_field.getString());
}
finally {
try { if (dataOut != null) dataOut.close(); }
catch (IOException ioe) {}
try { if (sc != null) sc.close(); }
catch (IOException ioe) {}
}
}
I hope you can help me with this.
Kind regards Michael.