Sunday, 8 September 2013

could not send Message from one device to another in android using jain-sip

could not send Message from one device to another in android using jain-sip

i have implemented a sip based request sending app in andorid which uses
jain-sip library.i have already changed the package name which is in jain
sip-api and jain sip-ri i have also chaned the package name of log4j
library to org1.*.the sip stack success fully created and listening point
has been made successfully but my code only works when i put both client
and server in same device if i put the server on other device the client
throws IO Exception.can any onew suggest how to implement it on both
devices i.e send message from one device to another...??? here is the code
for sending..
public void init(TextView tv) throws Exception { SipFactory sf=null;
sk=null;
sf=SipFactory.getInstance();
sf.setPathName("gov.nist");
Properties p=new Properties();
String peerHost="10.0.2.15:5002";
p.setProperty("javax.sip.OUTBOUND_PROXY",peerHost+"/"+ListeningPoint.TCP);
p.setProperty("javax.sip.STACK_NAME","stack");
sk=sf.createSipStack(p);
tv.setText("SipStack"+sk);
hf=sf.createHeaderFactory();
af=sf.createAddressFactory();
mf=sf.createMessageFactory();
ListeningPoint lp=sk.createListeningPoint(ip,port,ListeningPoint.TCP);
sp=sk.createSipProvider(lp);
tv.append("SipStack started on"+ip+port+ListeningPoint.TCP);
sp.addSipListener(this);
String fromName="me";
String fromSipAddress="me.com";
String fromDisplayName="I";
String toSipAddress="you.com";
String toUser="you";
String toDisplayName="YOU";
SipURI fromAddress=af.createSipURI(fromName,fromSipAddress);
Address fromNameAddress=af.createAddress(fromAddress);
fromNameAddress.setDisplayName(fromDisplayName);
FromHeader fh=hf.createFromHeader(fromNameAddress,"12345");
SipURI toAddress=af.createSipURI(toUser,toSipAddress);
Address toNameAddress=af.createAddress(toAddress);
toNameAddress.setDisplayName(toDisplayName);
ToHeader th=hf.createToHeader(toNameAddress,null);
SipURI requestUri=af.createSipURI(toUser,peerHost);
List<ViaHeader> vh=new ArrayList<ViaHeader>();
String ipAddress=lp.getIPAddress();
ViaHeader
vhh=hf.createViaHeader(ipAddress,lp.getPort(),lp.getTransport(),null);
vh.add(vhh);
ContentTypeHeader cth=hf.createContentTypeHeader("text","plain");
CallIdHeader cih=sp.getNewCallId();
CSeqHeader csh=hf.createCSeqHeader(1L,Request.INVITE);
MaxForwardsHeader mfh=hf.createMaxForwardsHeader(70);
Request
rqst=mf.createRequest(requestUri,Request.INVITE,cih,csh,fh,th,vh,mfh);
String host="10.0.2.15";
SipURI contactUrl=af.createSipURI(fromName,host);
contactUrl.setPort(8002);
contactUrl.setLrParam();
SipURI contactUri=af.createSipURI(fromName,host);
contactUri.setPort(sp.getListeningPoint(lp.getTransport()).getPort());
Address contactAddress=af.createAddress(contactUri);
contactAddress.setDisplayName(fromName);
contactHeader=hf.createContactHeader(contactAddress);
rqst.addHeader(contactHeader);
String sdpData="hey hello";
byte[] contents=sdpData.getBytes();
rqst.setContent(contents,cth);
ct=sp.getNewClientTransaction(rqst);
ct.sendRequest();
dg=ct.getDialog();
}

No comments:

Post a Comment