mjsip cant send message
<p>I have implementes an android program that can receive simple messages using the MJSIP, the problem is that I would like to be able to send messages too, my class is:</p>

<pre><code>package org.sipdroid.sipua.ui;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
import org.sipdroid.sipua.SipdroidEngine;
import org.zoolu.sip.address.NameAddress;
import org.zoolu.sip.address.SipURL;
import org.zoolu.sip.call.CallListenerAdapter;
import org.zoolu.sip.dialog.Dialog;
import org.zoolu.sip.dialog.InviteDialog;
import org.zoolu.sip.header.FromHeader;
import org.zoolu.sip.header.Header;
import org.zoolu.sip.header.RecordRouteHeader;
import org.zoolu.sip.header.ToHeader;
import org.zoolu.sip.message.Message;
import org.zoolu.sip.message.MessageFactory;
import org.zoolu.sip.message.SipMethods;
import org.zoolu.sip.message.SipResponses;
import org.zoolu.sip.provider.ConnectionIdentifier;
import org.zoolu.sip.provider.DialogIdentifier;
import org.zoolu.sip.provider.SipProvider;
import org.zoolu.sip.provider.SipProviderListener;
import org.zoolu.sip.provider.TransactionIdentifier;
import org.zoolu.sip.transaction.AckTransactionServer;
import org.zoolu.sip.transaction.AckTransactionServerListener;
import org.zoolu.sip.transaction.InviteTransactionServer;
import org.zoolu.sip.transaction.InviteTransactionServerListener;
import org.zoolu.sip.transaction.TransactionClient;
import org.zoolu.sip.transaction.TransactionClientListener;
import org.zoolu.sip.transaction.TransactionServer;
import org.zoolu.sip.transaction.TransactionServerListener;
import org.zoolu.tools.LogLevel;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.Reader;
import java.io.StringReader;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.util.Log;
public class IMHandler extends TransactionServer implements TransactionClientListener,SipProviderListener,TransactionServerListener,
                            InviteTransactionServerListener, AckTransactionServerListener,
                                                        TextToSpeech.OnInitListener{

private SipProvider sip_provider;
private Message message;
private TransactionServer ts;
private AckTransactionServer ack_ts;
private String callee;
private TextToSpeech mTts;
private String contact_url;

private boolean firstTime = true;






/** constructor */
public IMHandler(SipProvider sip_provider) {
    super(sip_provider);
    this.sip_provider = sip_provider;
    listen();
    Log.e("IMHandler"," &lt;Constructor&gt; IMHandler");

        mTts = new TextToSpeech(Receiver.mContext, this);
}


public void setMessage( Message message){
    this.message = message;
}


/** Starts a new InviteTransactionServer. */
public void listen() {
    ts = new TransactionServer(sip_provider,"MESSAGE", this);
    ts.listen();
    Log.e("IMHandler","&lt;listen&gt; LISTENING FOR INCOMING IM MSGS ....");
}



public void sendMessage(String callee, String caller, String contact,String session_descriptor, String icsi){
    this.callee = callee;
    this.contact_url = contact;
    Log.e("IMHandler","********** callee::"+callee+" caller::"+caller+" contact::"+contact+" *************");
    NameAddress to_url = new NameAddress(callee);
    NameAddress from_url = new NameAddress(caller);
    SipURL request_uri = to_url.getAddress();

    NameAddress contact_url = null;
    if (contact != null) {
        if (contact.indexOf("sip:") &gt;= 0)
            contact_url = new NameAddress(contact);
        else
            contact_url = new NameAddress(new SipURL(contact,sip_provider. getViaAddress(),sip_provider.getPort()));
    } else
        contact_url = from_url;

    Message messageIM = MessageFactory.createMessageRequest(sip_provider, to_url,  from_url, "HELLO", "text/plain", "HELLO WORLD");
    message = messageIM;
    sendIM(messageIM);
}



/**
 * Starts a new InviteTransactionClient and initializes the dialog state
 * information
 * 
 * @param invite
 *            the INVITE message
 */
public void sendIM(Message messageIM) {
    TransactionClient invite_tc = new TransactionClient(sip_provider, message, this);
    invite_tc.request();
}



@Override
public void onTransProvisionalResponse(
        org.zoolu.sip.transaction.TransactionClient tc, Message resp) {
    Log.e("IMHandler"," &lt;onTransProvisionalResponse&gt;  ##################");
    // TODO Auto-generated method stub

}



@Override
public void onTransSuccessResponse(
        org.zoolu.sip.transaction.TransactionClient tc, Message resp) {
    Log.e("IMHandler"," &lt;onTransSuccessResponse&gt;  ##################");
    // TODO Auto-generated method stub

}



@Override
public void onTransFailureResponse(
        org.zoolu.sip.transaction.TransactionClient tc, Message resp) {
    Log.e("IMHandler"," &lt;onTransFailureResponse&gt;  ##################");
    // TODO Auto-generated method stub

}



@Override
public void onTransTimeout(org.zoolu.sip.transaction.TransactionClient tc) {
    Log.e("IMHandler"," &lt;onTransTimeout&gt;  ##################");
    // TODO Auto-generated method stub

}


public Message sendResponce(String callee, String caller, String contact,Message req,NameAddress contact_address){
    this.callee = callee;

    Log.e("IMHandler","********** callee::"+callee+" caller::"+caller+" contact::"+contact+" *************");
    NameAddress to_url = new NameAddress(callee);
    NameAddress from_url = new NameAddress(caller);
    SipURL request_uri = to_url.getAddress();

    NameAddress contact_url = null;
    if (contact != null) {
        if (contact.indexOf("sip:") &gt;= 0)
            contact_url = new NameAddress(contact);
        else
            contact_url = new NameAddress(new SipURL(contact,sip_provider. getViaAddress(),sip_provider.getPort()));
    } else
        contact_url = from_url;
    Message resp = MessageFactory.createResponse(req, 200,SipResponses.reasonOf(200), contact_address);
}


@Override
public void onTransRequest(TransactionServer ts, Message req)  {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true); // never forget this! 
    DocumentBuilder builder;
    try {
            builder = domFactory.newDocumentBuilder();
            Log.e("IMHandler","&lt;onTransRequest&gt; parsing body:: "+ req.getBody());
            InputStream is = new ByteArrayInputStream(req.getBody().getBytes());
            final Document doc = builder.parse(is );

            NamespaceContext NMC = new NamespaceContext() {
                public String getNamespaceURI(String s) {
                    if (s.equals(XMLConstants.DEFAULT_NS_PREFIX))
                        return doc.lookupNamespaceURI(null);
                    else
                        return doc.lookupNamespaceURI(s);
                }

                public String getPrefix(String s) {
                    return doc.lookupPrefix(s);
                }

                public Iterator getPrefixes(String s) {
                    return null;
                }
            };

            NodeList nodes =doc.getChildNodes();// (NodeList) result;
            Log.e("IMHandler"," &lt;PARSING&gt;  *************** result ***********"+nodes.getLength());
            for (int i = 0; i &lt; nodes.getLength(); i++) {
                Log.e("IMHandler"," &lt;PARSING&gt;  *************** PARSING ***********");
                Log.e("IMHandler"," &lt;PARSING&gt;  NodeValue"+nodes.item(i).getNodeName());
                Log.e("IMHandler"," &lt;PARSING&gt;  *************** /PARSING ***********");
            }

    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String msg = req.getBody().replaceAll("&lt;(.|\n)*?&gt;","");
    if(firstTime ){
        Receiver.showIM();
        firstTime = false;
    }else{
        Receiver.getMessageListener().setFrom(req.getFromHeader().getValue());
        Receiver.getMessageListener().messageReceived(msg);
    }
    mTts.speak(msg,TextToSpeech.QUEUE_FLUSH,  null);

    NameAddress contact_address = new NameAddress("win@192.168.1.10");
    ConnectionIdentifier conn_id = ts.getConnectionId();

    Message resp = sendResponce(contact_address.toString(),"maxsap@192.168.1.9","maxsap@192.168.1.9",req,contact_address);
    ts.respondWith(resp);

    listen();
}








/**
 * Responds with &lt;i&gt;resp&lt;/i&gt;. This method can be called when the
 * InviteDialog is in D_INVITED or D_BYED states.
 * &lt;p&gt;
 * If the CSeq method is INVITE and the response is 2xx, it moves to state
 * D_ACCEPTED, adds a new listener to the SipProviderListener, and creates
 * new AckTransactionServer
 * &lt;p&gt;
 * If the CSeq method is INVITE and the response is not 2xx, it moves to
 * state D_REFUSED, and sends the response.
 */
public void respond(Message resp)
{
    Log.d("IMHandler","&lt;respond&gt; inside respond(resp)");
    String method = resp.getCSeqHeader().getMethod();
    int code = resp.getStatusLine().getCode();

        if (code &gt;= 200 &amp;&amp; code &lt; 300) {
            ts.terminate();
            ConnectionIdentifier conn_id = ts.getConnectionId();
            ack_ts = new AckTransactionServer(sip_provider, conn_id, resp,this);
            ack_ts.respond();
            return;
        } 
}




/**
 * Responds with &lt;i&gt;code&lt;/i&gt; and &lt;i&gt;reason&lt;/i&gt;. This method can be called
 * when the InviteDialog is in D_INVITED, D_ReINVITED states
 */
public void respond(int code, String reason, String contact,  Message req) {
    Log.d("InviteDialog","&lt;respond&gt; inside respond(" + code + "," + reason + ")");

        NameAddress contact_address = null;
        if (contact != null)
            contact_address = new NameAddress(contact);
        Message resp = MessageFactory.createResponse(req, code,
                reason, contact_address);
        respond(resp);
}


@Override
public void onTransAckTimeout(AckTransactionServer transaction) {
    Log.e("IMHandler"," &lt;onTransAckTimeout&gt;  ##################");
    // TODO Auto-generated method stub

}



@Override
public void onTransFailureAck(InviteTransactionServer ts, Message ack) {
    Log.e("IMHandler"," &lt;onTransFailureAck&gt;  ##################");
    // TODO Auto-generated method stub

}



@Override
public void onReceivedMessage(SipProvider sip_provider, Message message) {
    Log.e("IMHandler"," &lt;onReceivedMessage&gt;  ##################");

    //NameAddress contact_address = new NameAddress("win@192.168.1.10");
//  Message resp = MessageFactory.createResponse(req, 200,SipResponses.reasonOf(200), contact_address);
//  ts.respondWith(resp);

    // TODO Auto-generated method stub

}


// Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTts.setLanguage(Locale.US);
        if (result == TextToSpeech.LANG_MISSING_DATA ||
             result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("IMHandler", "Language is not available.");
        } else {
             Log.i("IMHandler", "Language found and TTS is initiated.");
        }
    } else {
        Log.e("IMHandler", "Could not initialize TextToSpeech.");
    }
}   
</code></pre>

<p>}</p>

<p>This class is able to receive a message send from a sip client and respond back. But I would like to initiate an im session using the send message method. I am initializing a transaction client and then call on the request method but nothing happens, no error no exception and no message is send.Can someone tell me what I am doing wrong?</p>

<p>regards maxsap</p>
