i hava problem with my midlet i need this midlet so i can register to our Sip server:192.168.100.1 ; username and password 7777
the problem this midlet can't register to Sip server and return the exception I made by declaring a Flag can get the request result from sip server , if not getting return false and thats always happend return false and directly return the exception
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.*;
import javax.microedition.sip.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
/**
* @author Java&C
*/
public class sip_reg4 extends MIDlet implements CommandListener {
private SipClientConnection sc = null;
private Display display;
private Form iForm;
private Command exitCommand;
private String realm;
private SipHeader sh;
int refreshID = 0 ;
int refreshStatus =0 ;
String contact = null;
SipRefreshHelper refHelper = null;
public sip_reg4()
{
display = Display.getDisplay(this);
iForm = new Form("sip_reg");
exitCommand = new Command("Exit",Command.EXIT,2);
iForm.addCommand(exitCommand);
iForm.setCommandListener(this);
doRegister(7777, 7777, null);
}
public void startApp() {
display.setCurrent(iForm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d) {
if (c== exitCommand )
{
notifyDestroyed();
}
}
public void doRegister(int username, int password, String realm) {
SipClientConnection scc = null;
SipConnectionNotifier scn = null;
try {
scn = (SipConnectionNotifier) Connector.open("sip:5060");
scc = (SipClientConnection) Connector.open("sip:192.168.100.1:5060");
contact = new String("sip:7777@"+scn.getLocalAddress()+":"+scn.getLocalPort());
scc.initRequest("REGISTER", scn);
scc.setHeader("From", "sip:7777@192.168.100.1");
scc.setHeader("To", "sip:7777@192.168.100.1");
scc.setHeader("Contact", contact);
scc.setCredentials(Integer.toString(username), Integer.toString(password), "192.168.100.1");
scc.send();
boolean flag = scc.receive(5000);
if(false == flag)
throw new RuntimeException("Response not arrived1");
if(scc.getStatusCode()!= 200)
throw new RuntimeException("status code "+ scc.getStatusCode());
scc.close();
} catch(Exception ex) {
iForm.append("exception"+" "+ ex.getMessage());
}
}
}

Reply With Quote

