4

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);

Débora
  • 5,816
  • 28
  • 99
  • 171
  • 2
    FYI: SIP and RTSP are two *different* session signaling protocols. SDP has nothing to do with sending requests: it describes the media session in a text-based format. RTSP and SIP may *use* SDP to setup the session. I would suggest reading the IETF RFCs to gain a better understanding of the protocols. (RTP: RFC3550, SDP: RFC4566, RTSP: RFC2326, SIP: RFC3261) – Ralf Dec 24 '11 at 07:01
  • Thank you Ralf. I am still new to these things. I ll take a look at what u suggested. Would you let me that whether one server can handle both SIP and RTSP, and send a response.(that means if the server has audio files,can the server send audio file in RTSP or SIP according the request?). The other thing is that does SDP goes with SIP and RTSP always describing the session/request or response content? – Débora Dec 24 '11 at 07:27
  • 1
    SIP & RTSP operate on different ports and are completely different protocols, I would say that it is highly unlikely that a server supports both, RTSP is typically used for file-based VOD media as well as live streaming (it has been described as a virtual VCR remote control with PLAY, STOP, PAUSE functionality), whereas SIP is often used in teleconferencing, conversational scenarios. Generally SDP is the widely-used protocol to describe a media session, although other standardization efforts exist. An SDP is typically the answer to an RTSP DESCRIBE, and features in SIP offer/answer exchanges. – Ralf Dec 24 '11 at 08:06
  • Thank you very much Ralf.I got an idea.If I am not obstructing you, would you let me know more about how both SDP and RTSP work together with example function.(I got a clear picture of SIP and RTSP from your explanation and thanks once again for that) – Débora Dec 24 '11 at 09:00

2 Answers2

2

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)

Dipan Mehta
  • 2,110
  • 1
  • 17
  • 31
  • Thank you very much Dipan.I already referred your first link.Also I took a look at your second link. – Débora Dec 28 '11 at 18:06
0

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

Débora
  • 5,816
  • 28
  • 99
  • 171