質問

I am creating a J2ME real time streaming audio player with RTP and through SIP connection. Also I am new for these things. I want to take look deeply those things. If any one know a good working sample code demonstrating an audio player streaming with RTP (That means how to send a REGISTER message to the server through SIP to get registered and send an INVITE message and get the response & play). Please let me know, highly appreciated.

Also I looked here

if

My server port is 6060
ip 111.111.111.1
id is myid password 123

Have I used the code correctly? If I am wrong, please make me correct.

public void doRegister(String username, String password, String realm) {

  SipClientConnection scc = null;  
  SipConnectionNotifier scn = null;  
  String contact = null;    
  try {   
      scn = (SipConnectionNotifier) Connector.open("sip:5080");   
      contact = new String("sip:myid:123@"+scn.getLocalAddress()+":"+scn.getLocalPort());   
      scc = (SipClientConnection) Connector.open("sip:111.111.111.1+"transport=tcp")  ; 
      scc.initRequest("REGISTER", scn);  
      scc.setHeader("From", "sip:myid:123@"+scn.getLocalAddress()+":5080");  
      scc.setHeader("To", "sip:myid:123@111.111.111.1");  
      scc.setHeader("Contact", contact);  
      scc.send();  
      boolean handled = false;  
      int scode = 0;        
      while(!handled) {
          SipHeader sh; 
          scc.receive(30000);
          scode = scc.getStatusCode();
          switch(scode){  
              case 401:
                  sh = new SipHeader("WWW-Authenticate",
                     scc.getHeader("WWW-Authenticate"));
                  realm = sh.getParameter("realm");                
                  scc.setCredentials(username, password, realm);
                  break;

              case 407:
                  sh = new SipHeader("Proxy-Authenticate", 
                  scc.getHeader("Proxy-Authenticate"));
                  realm = sh.getParameter("realm");                
                  scc.setCredentials(username, password, realm);
                  break;

              case 200: 
                  handled = true;
                  break;
              default:  
                handled = true;
          }  
      }
      scc.close();
  } catch(Exception ex) {
      // handle Exceptions
  }
 }

I got a respond with 180 Rigging message. Also let me know what is realm here. scc.setCredentials(username, password, realm);

役に立ちましたか?

解決 2

Many functions and more things are available and wide answer can be found here Also Nokia JSR180 API has sample codes as well

他のヒント

As you see here in example 1 - you realize that when you make a fresh Reqeust to server, where as server expects authentication it first sends 401. By seeing this the client can then either search for a password or ask the user. When server sends the 401 response code, it specifies which security domain is applicable for the given requests. This is already what you have got in your code :

realm = sh.getParameter("realm"); 

Once, failed, you need to send() the request again with credentials here. I guess the setCredentials() function is only setting these parameters inside the scc object and they will be applied when send() is called again.

Some references that might be of interest: http://www.developer.nokia.com/Community/Discussion/showthread.php?126760-SIP-registration-401-Unauthorized-.. (here people had issues related port number, which i am not sure if this is bothering you)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top