hi
I am new to j2me. I tried the following example.
For sending:-
public class SMSClient2t extends MIDlet
{
protected Display display;
protected Displayable displayable;
public SMSClient2t()
{
display = Display.getDisplay(this);
displayable = new Form("SMS Client");
}
public void startApp() {display.setCurrent(displayable);
try {
String myAddress = "sms://:4";
String hisAddress = "sms://9426729397:4";
String msg = "Hello";
MessageConnection smsconn =
(MessageConnection) Connector.open(myAddress);
TextMessage txtmessage =
(TextMessage)smsconn.newMessage(
MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(msg);
txtmessage.setAddress(hisAddress);
smsconn.send(txtmessage);
// get a reply back. Note, there could be a race
// condition here: while this server is waiting for
// a reply, someone else could send us a message
// which might slip in first... So we should really
// check it is from who we expect
Message replyMsg = smsconn.receive();
if (replyMsg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) replyMsg;
String replyText = tmsg.getPayloadText();
System.out.println("Reply: " + replyText);
}
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
display = null;
displayable = null;
}
}
for receiveing:-
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
/**
* @author vvachhani
*/
public class SMSServer2 extends MIDlet {
protected Display display;
protected Displayable displayable;
protected Form form;
public SMSServer2()
{
display = Display.getDisplay(this);
displayable = form = new Form("SMS Server");
}
public void startApp()
{
display.setCurrent(displayable);
try {
String addr = "sms://:4";
MessageConnection conn = (MessageConnection) Connector.open(addr);
Message msg = null;
while (true) {
// wait for incoming messages
msg = conn.receive(); // received a message
if (msg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) msg;
String receivedText = tmsg.getPayloadText();
form.append(new TextField("Message received", receivedText,
10, TextField.ANY));
// now send the message back
String replyText = "You sent: " + receivedText;
tmsg.setPayloadText(replyText);
conn.send(tmsg);
} else {
// Received message was not a text message, but e.g. binary ...
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional)
{
display = null;
displayable = null;
}
}
I can send the sms with port no but not able to recive it on same port no.
I use nokia 6233 mobile to run this application.
Please tel me how can get i get the port no of mobile?
Thanks
Alpesh shah
|