OK...
Here's my code (both sending and receiving apps). I tried the Receive app on a Nokia C3-01 - the closest I have to the devices you're using. I sent two messages, then called the phone (accepting the call), then terminated the call and sent a third message (without restarting the Receive app). All three messages were received.
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
public class Receive extends MIDlet implements CommandListener, Runnable {
private static final int PORT = 16666;
private static final Command EXIT = new Command("Exit", Command.EXIT, 1);
private Form form;
private MessageConnection con;
public void startApp() {
if (form == null) {
form = new Form("Receive");
form.addCommand(EXIT);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
(new Thread(this)).start();
}
}
public void commandAction(Command c, Displayable d) {
if (c == EXIT) {
try {
con.close();
} catch (Exception e) {
// swallow
}
notifyDestroyed();
}
}
public void run() {
try {
con = (MessageConnection) Connector.open("sms://:" + PORT);
println("Listening...");
while (true) {
Message m = con.receive();
if (m instanceof TextMessage) {
println(((TextMessage) m).getPayloadText());
} else {
println("[non-text]");
}
}
} catch (Exception e) {
println(e);
} finally {
println("Stopped listening.");
}
}
private void println(Object o) {
form.append((o.toString()) + "\n");
}
public void pauseApp() {
}
public void destroyApp(boolean b) {
}
}
Code:
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
public class Send extends MIDlet implements CommandListener {
private static final int PORT = 16666;
private static final Command EXIT = new Command("Exit", Command.EXIT, 1);
private static final Command SEND = new Command("Send", Command.OK, 1);
private Form form;
private TextField message;
private TextField number;
public void startApp() {
if (form == null) {
form = new Form("Send");
form.addCommand(EXIT);
form.addCommand(SEND);
message = new TextField("Message", "", 140, TextField.ANY);
form.append(message);
number = new TextField("Send to", "+", 20, TextField.PHONENUMBER);
form.append(number);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
}
}
public void commandAction(Command c, Displayable d) {
if (c == EXIT) {
notifyDestroyed();
} else if (c == SEND) {
send();
}
}
private void send() {
println("Sending...");
try {
MessageConnection con = (MessageConnection) Connector.open("sms://" + number.getString() + ":" + PORT);
try {
TextMessage msg = (TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(message.getString());
con.send(msg);
println("Sent.");
} finally {
con.close();
}
} catch (IOException e) {
println(e);
}
}
private void println(Object o) {
form.append((o.toString()) + "\n");
}
public void pauseApp() {
}
public void destroyApp(boolean b) {
}
}