SIP 서버단 구축 질문입니다.


안녕하세요. 음성통신 구축을 해보려고 하는데요.

클라이언트단은 linphone 같은걸 임시로 쓰기로 했는데 SIP 음성서버를 만드려고 하는데 막히네요. 톰켓이 SipServlet을 지원해서 해보니까 서버 URL이 뭔지 또 tcp://인지 http://인지도 모르겠구요. 뭔가 흐지부지된 느낌입니다. 일단은 소스를 이렇게 짜봤는데요.

//여기에 코드를 입력하세요
package sip;
import java.io.IOException;
import java.util.HashMap;
import javax.servlet.*;
import javax.servlet.sip.*;
/**
 * EchoServlet provides a simple example of a SIP servlet.
 * EchoServlet echoes instant messages sent by Windows Messenger.
 */
public class EchoServlet extends SipServlet {
  /**
   * _address keeps the mapping between sign-in name and actual contact address.
   */
  protected HashMap _addresses = new HashMap();
  /**
   * Invoked for SIP INVITE requests, which are sent by Windows Messenger to establish a chat session.
   */
  protected void doInvite(SipServletRequest req) throws IOException, ServletException {
    // We accept invitation for a new session by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }
  /**
   * Invoked for SIP REGISTER requests, which are sent by Windows Messenger for sign-in and sign-off.
   */
  protected void doRegister(SipServletRequest req) throws IOException, ServletException {
    String aor = req.getFrom().getURI().toString().toLowerCase();
    System.out.println(aor + "이 등록하려 합니다.");
    synchronized (_addresses) {
      // The non-zero value of Expires header indicates a sign-in.
      if (req.getExpires() != 0) {
        // Keep the name/address mapping.
        _addresses.put(aor, req.getAddressHeader("Contact").getURI());
      }
      // The zero value of Expires header indicates a sign-off.
      else {
        // Remove the name/address mapping.
        _addresses.remove(aor);
      }
    }
    // We accept the sign-in or sign-off by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }
  /**
   * Invoked for SIP MESSAGE requests, which are sent by Windows Messenger for instant messages.
   */
  protected void doMessage(SipServletRequest req) throws IOException, ServletException {
    SipURI uri = null;
    synchronized (_addresses) {
      // Get the previous registered address for the sender.
      uri = (SipURI) _addresses.get(req.getFrom().getURI().toString().toLowerCase());
    }
    if (uri == null) {
      // Reject the message if it is not from a registered user.
      req.createResponse(SipServletResponse.SC_FORBIDDEN).send();
      return;
    }
    // We accept the instant message by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
    // Create an echo SIP MESSAGE request with the same content.
    SipServletRequest echo = req.getSession().createRequest("MESSAGE");
    String charset = req.getCharacterEncoding();
    if (charset != null) {
      echo.setCharacterEncoding(charset);
    }
    echo.setRequestURI(uri);
    echo.setContent(req.getContent(), req.getContentType());
    // Send the echo MESSAGE request back to Windows Messenger.
    echo.send();
  }
  /**
   * Invoked for SIP 2xx class responses.
   */
  protected void doSuccessResponse(SipServletResponse resp) throws IOException, ServletException {
    // Print out when the echo message was accepted.
    if (resp.getMethod().equalsIgnoreCase("MESSAGE")) {
       System.out.println("\"" + resp.getRequest().getContent() + "\" was accepted: " + resp.getStatus());
    }
  }
  /**
   * Invoked for SIP 4xx-6xx class responses.
   */
  protected void doErrorResponse(SipServletResponse resp) throws IOException, ServletException {
    // Print out when the echo message was rejected/
    if (resp.getMethod().equalsIgnoreCase("MESSAGE")) {
       System.out.println("\"" + resp.getRequest().getContent() + "\" was rejected: " + resp.getStatus());
    }
  }
  /**
   * Invoked for SIP BYE requests, which are sent by Windows Messenger to terminate a chat session/
   */
  protected void doBye(SipServletRequest req) throws IOException, ServletException {
    // Accept session termination by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }
}

도와주세요. 감사합니다.

  • 2016년 08월 28일에 작성됨
    개발을 공부하는 학생 ANDROID / IOS / JSP / VB.NET / AWS

조회수 155


로그인이 필요한 기능입니다.

Hashcode는 개발자들을 위한 무료 QnA사이트 입니다. 작성한 답변에 다른 개발자들이 댓글을 작성하거나 좋아요/싫어요를 할 수 있기 때문에 계정을 필요로 합니다.
► 로그인
► 계정만들기
Close