mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Apply builder pattern to ConnectionConfiguration
Introducing a clean split between the constant connection configuration parameters, which are now all in ConnectionConfiguration and the dynamic connection state (e.g. hostAddresses) which are now in AbstractXMPPConnection. Also removed all arguments of login() since the username, password, resource and callback handler need now to be configured via ConnectionConfiguration. Also remove documentation/extensions/messageevents.md, as it's already in documentation/legacy
This commit is contained in:
parent
69f387b344
commit
c81cd34561
24 changed files with 760 additions and 708 deletions
|
@ -28,18 +28,21 @@ Connect and Disconnect
|
|||
----------------------
|
||||
|
||||
```
|
||||
// Create the configuration for this new connection_
|
||||
ConnectionConfiguration config = new ConnectionConfiguration("jabber.org", 5222);
|
||||
// Create the configuration for this new connection
|
||||
XMPPTCPConnectionConfigurationBuilder configBuilder = XMPPTCPConnectionConfiguration.builder();
|
||||
configBuilder.setUsernameAndPassword("username", "password");
|
||||
configBuilder.setResource("SomeResource");
|
||||
configBuilder.setServiceName("jabber.org");
|
||||
|
||||
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
|
||||
// Connect to the server_
|
||||
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
|
||||
// Connect to the server
|
||||
connection.connect();
|
||||
// Log into the server_
|
||||
connection.login("username", "password", "SomeResource");
|
||||
// Log into the server
|
||||
connection.login();
|
||||
|
||||
...
|
||||
|
||||
// Disconnect from the server_
|
||||
// Disconnect from the server
|
||||
connection.disconnect();
|
||||
```
|
||||
|
||||
|
|
|
@ -34,9 +34,7 @@ receive the roster entries.
|
|||
In this example we can see how user1 sends his roster to user2.
|
||||
|
||||
```
|
||||
// Connect to the server and log in
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
XMPPConnection conn1 = …
|
||||
|
||||
// Create a new roster exchange manager on conn1
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
|
@ -64,9 +62,7 @@ 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.
|
||||
|
||||
```
|
||||
// Connect to the server and log in
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
XMPPConnection conn1 = …
|
||||
|
||||
// Create a new roster exchange manager on conn1
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
|
@ -95,9 +91,7 @@ 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.
|
||||
|
||||
```
|
||||
// Connect to the server and log in
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
XMPPConnection conn1 = …
|
||||
|
||||
// Create a new roster exchange manager on conn1
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
|
@ -127,10 +121,9 @@ adds the received entries to his roster.
|
|||
|
||||
```
|
||||
// Connect to the server and log in the users
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
conn2 = new XMPPConnection(host);
|
||||
conn2.login(server_user2, pass2);
|
||||
XMPPConnection conn1 = …
|
||||
XMPPConnection conn2 = …
|
||||
|
||||
final Roster user2_roster = conn2.getRoster();
|
||||
|
||||
// Create a RosterExchangeManager that will help user2 to listen and accept
|
||||
|
|
|
@ -44,13 +44,19 @@ The `XMPPTCPConnection` class is used to create a connection to an XMPP
|
|||
server. Below are code examples for making a connection:
|
||||
|
||||
```
|
||||
// Create a connection to the jabber.org server._
|
||||
XMPPConnection conn1 = **new** XMPPTCPConnection("jabber.org");
|
||||
// Create a connection to the jabber.org server.
|
||||
AbstractXMPPConnection conn1 = **new** XMPPTCPConnection("username", "password" "jabber.org");
|
||||
conn1.connect();
|
||||
|
||||
// Create a connection to the jabber.org server on a specific port._
|
||||
ConnectionConfiguration config = new ConnectionConfiguration("jabber.org", 5222);
|
||||
XMPPConnection conn2 = **new** XMPPTCPConnection(config);
|
||||
// Create a connection to the jabber.org server on a specific port.
|
||||
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
|
||||
.setUsernameAndPassword("username", "password")
|
||||
.setServiceName("jabber.org")
|
||||
.setHost("earl.jabber.org")
|
||||
.setPort("8222")
|
||||
.build();
|
||||
|
||||
AbstractXMPPConnection conn2 = **new** XMPPTCPConnection(config);
|
||||
conn2.connect();
|
||||
```
|
||||
|
||||
|
@ -60,10 +66,10 @@ ConnectionConfiguration class provides advanced control over the connection
|
|||
created, such as the ability to disable or require encryption. See
|
||||
[XMPPConnection Management](connections.html) for full details.
|
||||
|
||||
Once you've created a connection, you should login using a username and
|
||||
password with the `XMPPConnection.login(String username, String password)`
|
||||
method. Once you've logged in, you can being chatting with other users by
|
||||
creating new `Chat` or `GroupChat` objects.
|
||||
Once you've created a connection, you should login with the
|
||||
`XMPPConnection.login()` method. Once you've logged in, you can being
|
||||
chatting with other users by creating new `Chat` or `GroupChat`
|
||||
objects.
|
||||
|
||||
Working with the Roster
|
||||
----------------------
|
||||
|
|
|
@ -12,9 +12,9 @@ Smack Key Advantages
|
|||
* Extremely simple to use, yet powerful API. Sending a text message to a user can be accomplished in only a few lines of code:
|
||||
|
||||
```java
|
||||
AbstractXMPPConnection connection = new XMPPTCPConnection("jabber.org");
|
||||
AbstractXMPPConnection connection = new XMPPTCPConnection("mtucker", "password", "jabber.org");
|
||||
connection.connect();
|
||||
connection.login("mtucker", "password");
|
||||
connection.login();
|
||||
Chat chat = ChatManager.getInstanceFor(connection)
|
||||
.createChat("jsmith@jivesoftware.com", new MessageListener() {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue