1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Make XMPPConnection an interface

create AbstractXMPPConnection.
This commit is contained in:
Florian Schmaus 2014-05-25 12:28:08 +02:00
parent 6dd180e9d3
commit beecb8a675
33 changed files with 1264 additions and 1090 deletions

View file

@ -20,8 +20,8 @@
<p>
The <tt>org.jivesoftware.smack.XMPPConnection</tt> class manages your connection to an XMPP
server. The default implementation is the <tt>org.jivesoftware.smack.XMPPConnection</tt>
class. Two constructors are mainly used. The first, <tt>XMPPConnection(String)</tt> takes
server. A default implementation is the <tt>org.jivesoftware.smack.XMPPTCPConnection</tt>
class. Two constructors are mainly used. The first, <tt>XMPPTCPConnection(String)</tt> takes
the server name you'd like to connect to as an argument. All default connection settings will
be used:
<ul>
@ -33,7 +33,7 @@
<li>The XMPP resource name "Smack" will be used for the connection.</li>
</ul>
Alternatively, you can use the <tt>XMPPServer(ConnectionConfiguration)</tt> constructor to
Alternatively, you can use the <tt>XMPPTCPConnection(ConnectionConfiguration)</tt> constructor to
specify advanced connection settings. Some of these settings include:
<ul>
@ -61,9 +61,8 @@
<font color="gray"><i>// Create the configuration for this new connection</i></font>
ConnectionConfiguration config = new ConnectionConfiguration(<font color="green">"jabber.org"</font>, 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
Connection connection = new XMPPConnection(config);
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
<font color="gray"><i>// Connect to the server</i></font>
connection.connect();
<font color="gray"><i>// Log into the server</i></font>
@ -80,7 +79,7 @@ manager will try to immediately reconnect to the server and increase the delay b
successive reconnections keep failing.</i>
<br>
In case you want to force a reconnection while the reconnetion manager is waiting for the next
reconnection, you can just use <i>XMPPConnection#connect()</i> and a new attempt will be made.
reconnection, you can just use <i>AbstractXMPPConnection#connect()</i> and a new attempt will be made.
If the manual attempt also failed then the reconnection manager will still continue the
reconnection job.
</p>

View file

@ -26,7 +26,7 @@ Debugging mode can be enabled in two different ways:
<ol>
<li>Add the following line of code <b>before</b> creating new connections:<p>
<tt>XMPPConnection.DEBUG_ENABLED = true;</tt><p>
<tt>SmackConfiguration.DEBUG_ENABLED = true;</tt><p>
<li>Set the Java system property <tt>smack.debugEnabled</tt> to true. The
system property can be set on the command line such as:<p>
@ -39,7 +39,7 @@ add the following line to your application before opening new connections:
</p>
<p>
<tt>XMPPConnection.DEBUG_ENABLED = false;</tt>
<tt>SmackConfiguration.DEBUG_ENABLED = false;</tt>
</p>
<p>

View file

@ -99,9 +99,9 @@ for notifications and will send the message to the other user. The other user wi
to a <i>MessageEventManager</i> that will listen and react to the event notification requested by the other user.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in the users</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
conn2 = new XMPPConnection(host);
conn2 = new XMPPTCPConnection(host);
conn2.login(server_user2, pass2);
<font color="#3f7f5f">// User2 creates a MessageEventManager</font>
@ -195,7 +195,7 @@ to a <i>MessageEventManager</i> that will listen and react to the event notifica
the requests for notifications and sends the message.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
<font color="#3f7f5f">// Create a MessageEventManager</font>
@ -241,4 +241,4 @@ the requests for notifications and sends the message.
</body>
</html>
</html>

View file

@ -39,7 +39,7 @@ the second parameter is the id of the user that will receive the roster entries.
In this example we can see how user1 sends his roster to user2.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
@ -69,7 +69,7 @@ the second parameter is the id of the user that will receive the roster entries.
In this example we can see how user1 sends his roster groups to user2.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
@ -100,7 +100,7 @@ the second parameter is the id of the user that will receive the roster entries.
In this example we can see how user1 sends a roster entry to user2.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
@ -135,9 +135,9 @@ In this example we can see how user1 sends a roster entry to user2 and user2 add
entries to his roster.
<blockquote>
<pre> <font color="#3f7f5f">// Connect to the server and log in the users</font>
conn1 = new XMPPConnection(host);
conn1 = new XMPPTCPConnection(host);
conn1.login(server_user1, pass1);
conn2 = new XMPPConnection(host);
conn2 = new XMPPTCPConnection(host);
conn2.login(server_user2, pass2);
final Roster user2_roster = conn2.getRoster();
@ -176,4 +176,4 @@ entries to his roster.
</blockquote>
</body>
</html>
</html>

View file

@ -76,18 +76,19 @@ list of initializers.
Establishing a Connection
</p>
The <tt>XMPPConnection</tt> class is used to create a connection to an
XMPP server. Below are code examples for making a connection:<p>
The classes subclassing <tt>AbstractXMPPConnection</tt> are used to
create a connection to an XMPP server. Below are code examples for
making a connection:<p>
<div class="code">
<pre>
<font color="gray"><i>// Create a connection to the jabber.org server.</i></font>
Connection conn1 = <font color="navy"><b>new</b></font> XMPPConnection(<font color="green">"jabber.org"</font>);
AbstractXMPPConnection conn1 = <font color="navy"><b>new</b></font> XMPPTCPConnection(<font color="green">"jabber.org"</font>);
conn1.connect();
<font color="gray"><i>// Create a connection to the jabber.org server on a specific port.</i></font>
ConnectionConfiguration config = new ConnectionConfiguration(<font color="green">"jabber.org"</font>, 5222);
Connection conn2 = <font color="navy"><b>new</b></font> XMPPConnection(config);
AbstractXMPPConnection conn2 = <font color="navy"><b>new</b></font> XMPPTCPConnection(config);
conn2.connect();
</pre></div>
@ -97,7 +98,7 @@ conn2.connect();
<a href="connections.html">XMPPConnection Management</a> for full details.</p>
<p>Once you've created a connection, you should login using a username and password
with the <tt>XMPPConnection.login(String username, String password)</tt> method.
with the <tt>AbstractXMPPConnection.login(String username, String password)</tt> method.
Once you've logged in, you can being chatting with other users by creating
new <tt>Chat</tt> or <tt>GroupChat</tt> objects.
@ -130,7 +131,7 @@ and "out fishing":<p>
<font color="gray"><i>// Create a new presence. Pass in false to indicate we're unavailable.</i></font>
Presence presence = new Presence(Presence.Type.unavailable);
presence.setStatus(<font color="green">"Gone fishing"</font>);
<font color="gray"><i>// Send the packet (assume we have a XMPPConnection instance called "con").</i></font>
<font color="gray"><i>// Send the packet (assume we have a AbstractXMPPConnection instance called "con").</i></font>
con.sendPacket(presence);
</pre></div>
<p>