📄 sipclientconnection.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.4.2_10) on Wed Feb 28 12:31:09 CET 2007 -->
<TITLE>
SipClientConnection (JSR180 SIP API for J2ME)
</TITLE>
<META NAME="keywords" CONTENT="javax.microedition.sip.SipClientConnection interface">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="SipClientConnection (JSR180 SIP API for J2ME)";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
PREV CLASS
<A HREF="../../../javax/microedition/sip/SipClientConnectionListener.html" title="interface in javax.microedition.sip"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" target="_top"><B>FRAMES</B></A>
<A HREF="SipClientConnection.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
javax.microedition.sip</FONT>
<BR>
Interface SipClientConnection</H2>
<DL>
<DT><B>All Superinterfaces:</B> <DD>javax.microedition.io.Connection, <A HREF="../../../javax/microedition/sip/SipConnection.html" title="interface in javax.microedition.sip">SipConnection</A></DD>
</DL>
<HR>
<DL>
<DT>public interface <B>SipClientConnection</B><DT>extends <A HREF="../../../javax/microedition/sip/SipConnection.html" title="interface in javax.microedition.sip">SipConnection</A></DL>
<P>
<tt>SipClientConnection</tt> represents a SIP client transaction. Applications can create a new <tt>SipClientConnection</tt> with <tt>Connector</tt> or <tt>SipDialog</tt> object.<p> <A NAME="CLIENT_STATE_DIAGRAM">The <tt>SipClientConnection</tt> has following state diagram:<br></A> <img src="./jsr180-client-state-diagram.gif"> <UL> <LI> <em>Created</em>, <tt>SipClientConnection</tt> created using <tt>Connector</tt> <LI> <em>Initialized</em>, request has been initialized with <A HREF="SipClientConnection.html#initRequest(java.lang.String, javax.microedition.sip.SipConnectionNotifier)"><tt>initRequest(...)</tt></A> or <A HREF="SipClientConnection.html#initAck()"><tt>initAck()</tt></A> or <A HREF="SipClientConnection.html#initCancel()"><tt>initCancel()</tt></A> or <A HREF="SipDialog.html#getNewClientConnection(java.lang.String)"><tt>SipDialog.getNewClientConnection(...)</tt></A> <LI> <em>Stream Open</em>, <tt>OutputStream</tt> opened with <A HREF="SipConnection.html#openContentOutputStream()"><tt>openContentOutputStream()</tt></A>. Opening <tt>InputStream</tt> for received response does not trigger state transition. <LI> <em>Proceeding</em>, request has been sent, waiting for the response, or provisional 1xx response received for an INVITE request. <tt>initCancel()</tt> can be called, which will spawn a new <tt>SipClientConnection</tt> which is in <em>Initialized</em> state <LI> <em>Completed</em>, transaction completed with final response (2xx, 3xx, 4xx, 5xx, 6xx) in this state the ACK can be initialized. Multiple 200 OK responses can be received. Note different state transition for responses 401 and 407. <LI> <em>Unauthorized</em>, transaction completed with response 401 (Unauthorized) or 407 (Proxy Authentication Required). The application can re-originate the request with proper credentials by calling <A HREF="SipClientConnection.html#setCredentials(java.lang.String, java.lang.String, java.lang.String)"><tt>setCredentials()</tt></A> method. After this the <tt>SipClientConnection</tt> is back in <em>Proceeding</em> state. <LI> <em>Terminated</em>, the final state, in which the SIP connection has been terminated by error or closed </UL> <FONT SIZE="2"><b>Note:</b> The state diagram of <tt>SipClientConnection</tt> differs from the state diagram of SIP client transaction, which can be found in RFC 3261 [1] p.128-133</FONT> <br> <br> Following methods are restricted to a certain state. The table shows the list of restricted methods allowed in each state. <br><br> <UL> <LI> <em>Created</em><br><code> initRequest<br></code> <LI> <em>Initialized</em><br><code> addHeader<br> setHeader<br> removeHeader<br> setRequestURI<br> openContentOutputStream<br> send<br> enableRefresh<br> setCredentials<br></code> <LI> <em>Stream Open</em><br> Methods in <code>OutputStream</code> and <code>SipConnection.send</code> <LI> <em>Proceeding</em><br><code> receive<br> openContentInputStream<br> initCancel<br></code> <LI> <em>Completed</em><br><code> openContentInputStream<br> initAck<br> receive<br></code> <LI> <em>Unauthorized</em><br><code> setCredentials<br></code> <LI> <em>Terminated</em><br> The transaction and this connection is closed. The methods above throw <tt>SipException.INVALID_STATE</tt> if that is specified to the method and <tt>IOException</tt> for those methods (e.g. methods of Input/OutputStream) that does not have <tt>SipException</tt> specified. Methods that don't throw checked exceptions return without any action or return <tt>null</tt> as appropriate. </tt> </UL> Following methods can be called in every state. The functionality is defined by the method depending on the information availability. <UL> <LI> <em>Can be called in every state (with the exception of setListener and setErrorListener)</em>. Accessors return <tt>null</tt> in the <em>Terminated</em> state.<br><code> getHeader<br> getHeaders<br> getRequestURI<br> getMethod<br> getStatusCode<br> getReasonPhrase<br> getDialog<br> setListener // can not be called in <em>Terminated</em> state<br> setErrorListener // can not be called in <em>Terminated</em> state<br> close </code> // causes state transition to <em>Terminated</em> state </UL> <H3>Code examples</H3> The example below illustrates the usage of SIP client connection: opening, sending one request (MESSAGE) and receiving response: <p><p> <pre> public void sendTextMessage(String msg) { SipClientConnection sc = null; try { sc = (SipClientConnection) Connector.open ("sip:sippy.tester@host.com:5060"); sc.initRequest("MESSAGE", null); sc.setHeader("From", "sip:user@host.com"); sc.setHeader("Subject", "testing..."); // write message body sc.setHeader("Content-Type", "text/plain"); sc.setHeader("Content-Length", Integer.toString(msg.length())); OutputStream os = sc.openContentOutputStream(); os.write(msg.getBytes()); os.close(); // close stream and send the message // wait maximum 15 seconds for response boolean ok = sc.receive(15000); if(ok) { // response received if(sc.getStatusCode() == 200) { // handle 200 OK response } else { // handle possible error responses } } sc.close(); } catch(Exception ex) { // handle Exceptions } } </pre> Following class shows the same example using callback listener interface: <p><p> <pre> public class SipClient implements SipClientConnectionListener { public void sendTextMessage(String msg) { SipClientConnection sc = null; try { sc = (SipClientConnection) Connector.open ("sip:sippy.tester@host.com:5060"); sc.setListener(this); sc.initRequest("MESSAGE", null); sc.setHeader("From", "sip:user@host.com"); sc.setHeader("Subject", "testing..."); sc.setHeader("Content-Type", "text/plain"); sc.setHeader("Content-Length", Integer.toString(msg.length())); OutputStream os = sc.openContentOutputStream(); os.write(msg.getBytes()); os.close(); // close stream and send message } catch(Exception ex) { // handle Exceptions } return; } public void notifyResponse(SipClientConnection scn) { try { // retrieve the response received sc.receive(0); // does not block response is there if(sc.getStatusCode() == 200) { // handle 200 OK response } else { // handle possible error responses } sc.close(); } catch(Exception ex) { // handle Exceptions } } } </pre>
<P>
<P>
<DL>
<DT><B>See Also:</B><DD><A HREF="../../../javax/microedition/sip/SipClientConnectionListener.html" title="interface in javax.microedition.sip"><CODE>SipClientConnectionListener</CODE></A>, <A HREF="../../../javax/microedition/sip/SipConnectionNotifier.html" title="interface in javax.microedition.sip"><CODE>SipConnectionNotifier</CODE></A>, <A HREF="../../../javax/microedition/sip/SipServerConnection.html" title="interface in javax.microedition.sip"><CODE>SipServerConnection</CODE></A>, <A HREF="../../../javax/microedition/sip/SipDialog.html#getNewClientConnection(java.lang.String)"><CODE>SipDialog.getNewClientConnection(String)</CODE></A></DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -