SIP & JAVA
Hi,
I am trying to make a java chat klient using SIP, but i can't get it to work:
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.sip.*;
publicclass sipClassimplements CommandListener{
privatestaticfinal String appTitle ="SIP";
private String sipAddress ="Somebody@192.168.1.99";
privateint portReceive = 5060;
privateint portSend = 5060;
private String message ="Some Message Body";
private String msgSubject ="Test Message";
private SipClientConnection sc =null;
private SipConnectionNotifier scn =null;
private SipServerConnection ssc =null;
public sipClass(){
super();
}
publicstaticvoid main(String [] args){
sipTrade st =new sipTrade();
st.receiveTextMessage();
}
publicvoid receiveTextMessage(){
Thread receiveThread =new ReceiveThread();
receiveThread.start();
}
/** Receive Message Thread */
class ReceiveThreadextends Thread{
privatebyte buffer[] =newbyte[0xFF];
publicvoid run(){
try{
scn = (SipConnectionNotifier)
Connector.open("sip:" + portReceive);
System.out.print("Listening at " + portReceive +"...");
// block and wait for incoming request.
// SipServerConnection is established and returned
// when a new request is received.
ssc = scn.acceptAndOpen();
if (ssc.getMethod().equals("MESSAGE")){
String contentType = ssc.getHeader("Content-Type");
if ( (contentType !=null) &&
contentType.equals("text/plain")){
InputStream is = ssc.openContentInputStream();
int bytesRead;
String msg =new String("");
while ((bytesRead = is.read(buffer)) != -1){
msg +=new String(buffer, 0, bytesRead);
}
System.out.print("\n...Message Received\n");
System.out.print("Respose: \"" + msg +"\"\n\n");
}
// initialize SIP 200 OK and send it back
ssc.initResponse(200);
ssc.send();
System.out.print("Response sent...\n");
}
ssc.close();
}catch(Exception ex){
// IOException
// InterruptedIOException
// SecurityException
// SipException
System.out.print("MIDlet: exception " + ex.getMessage());
ex.printStackTrace();
}
}
}
}
can someone please help me? what i am trying to do for starter is simply reciving messages i am sending trough x-lite....

