本文整理汇总了Java中org.jivesoftware.smack.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于org.jivesoftware.smack包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
public XMPPConnection init() {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
ConnectionConfiguration connectionConfig = new ConnectionConfiguration(Const.XMPP_HOST, Const.XMPP_PORT);
// connectionConfig.setSASLAuthenticationEnabled(false);//
// 不使用SASL验证,设置为false
// connectionConfig
// .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// 允许自动连接
connectionConfig.setReconnectionAllowed(true);
// 允许登陆成功后更新在线状态
connectionConfig.setSendPresence(true);
// 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
XMPPConnection connection = new XMPPConnection(connectionConfig);
return connection;
}
示例2: getJoinedRooms
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
* contain Strings where each String represents a room (e.g. [email protected]).
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. [email protected]
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
}
catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}
示例3: AgentRoster
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Constructs a new AgentRoster.
*
* @param connection an XMPP connection.
*/
AgentRoster(Connection connection, String workgroupJID) {
this.connection = connection;
this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();
listeners = new ArrayList<AgentRosterListener>();
presenceMap = new HashMap<String, Map<String, Presence>>();
// Listen for any roster packets.
PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
connection.addPacketListener(new AgentStatusListener(), rosterFilter);
// Listen for any presence packets.
connection.addPacketListener(new PresencePacketListener(),
new PacketTypeFilter(Presence.class));
// Send request for roster.
AgentStatusRequest request = new AgentStatusRequest();
request.setTo(workgroupJID);
connection.sendPacket(request);
}
示例4: getServiceNames
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns a collection with the XMPP addresses of the Multi-User Chat services.
*
* @param connection the XMPP connection to use for discovering Multi-User Chat services.
* @return a collection with the XMPP addresses of the Multi-User Chat services.
* @throws XMPPException if an error occured while trying to discover MUC services.
*/
public static Collection<String> getServiceNames(Connection connection) throws XMPPException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
DiscoverItems.Item item = it.next();
try {
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature("http://jabber.org/protocol/muc")) {
answer.add(item.getEntityID());
}
}
catch (XMPPException e) {
// Trouble finding info in some cases. This is a workaround for
// discovering info on remote servers.
}
}
return answer;
}
示例5: getRoomMultiplexor
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns a new or existing RoomListenerMultiplexor for a given connection.
*
* @param conn the connection to monitor for room invitations.
* @return a new or existing RoomListenerMultiplexor for a given connection.
*/
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn)) {
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
new RoomMultiplexListener());
rm.init();
// We need to use a WeakReference because the monitor references the
// connection and this could prevent the GC from collecting the monitor
// when no other object references the monitor
monitors.put(conn, new WeakReference<RoomListenerMultiplexor>(rm));
}
// Return the InvitationsMonitor that monitors the connection
return monitors.get(conn).get();
}
}
示例6: getRoomMultiplexor
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns a new or existing RoomListenerMultiplexor for a given connection.
*
* @param conn the connection to monitor for room invitations.
* @return a new or existing RoomListenerMultiplexor for a given connection.
*/
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn) || monitors.get(conn).get() == null) {
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
new RoomMultiplexListener());
rm.init();
// We need to use a WeakReference because the monitor references the
// connection and this could prevent the GC from collecting the monitor
// when no other object references the monitor
monitors.put(conn, new WeakReference<RoomListenerMultiplexor>(rm));
}
// Return the InvitationsMonitor that monitors the connection
return monitors.get(conn).get();
}
}
示例7: setServiceEnabled
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Enable the Jabber services related to file transfer on the particular
* connection.
*
* @param connection The connection on which to enable or disable the services.
* @param isEnabled True to enable, false to disable.
*/
public static void setServiceEnabled(final Connection connection,
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (isEnabled) {
if (!manager.includesFeature(namespace)) {
manager.addFeature(namespace);
}
} else {
manager.removeFeature(namespace);
}
}
}
示例8: getReply
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
static public Packet getReply(Connection connection, Packet packet, long timeout)
throws XMPPException
{
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
connection.sendPacket(packet);
// Wait up to a certain number of seconds for a reply.
Packet result = response.nextResult(timeout);
// Stop queuing results
response.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getError() != null) {
throw new XMPPException(result.getError());
}
return result;
}
示例9: isServiceEnabled
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Checks to see if all file transfer related services are enabled on the
* connection.
*
* @param connection The connection to check
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final Connection connection) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (!manager.includesFeature(namespace)) {
return false;
}
}
return true;
}
示例10: RoomListenerMultiplexor
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* All access should be through
* the static method {@link #getRoomMultiplexor(Connection)}.
*/
private RoomListenerMultiplexor(Connection connection, RoomMultiplexFilter filter,
RoomMultiplexListener listener) {
if (connection == null) {
throw new IllegalArgumentException("Connection is null");
}
if (filter == null) {
throw new IllegalArgumentException("Filter is null");
}
if (listener == null) {
throw new IllegalArgumentException("Listener is null");
}
this.connection = connection;
this.filter = filter;
this.listener = listener;
}
示例11: getSearchForm
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns the form for all search fields supported by the search service.
*
* @param con the current Connection.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return the search form received by the server.
* @throws org.jivesoftware.smack.XMPPException
* thrown if a server error has occurred.
*/
public Form getSearchForm(Connection con, String searchService) throws XMPPException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.GET);
search.setTo(searchService);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
con.sendPacket(search);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
return Form.getFormFrom(response);
}
示例12: save
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Save this vCard for the user connected by 'connection'. Connection should be authenticated
* and not anonymous.<p>
* <p/>
* NOTE: the method is asynchronous and does not wait for the returned value.
*
* @param connection the Connection to use.
* @throws XMPPException thrown if there was an issue setting the VCard in the server.
*/
public void save(Connection connection) throws XMPPException {
checkAuthenticated(connection, true);
setType(IQ.Type.SET);
setFrom(connection.getUser());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
connection.sendPacket(this);
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
}
示例13: getSharedGroups
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Returns the collection that will contain the name of the shared groups where the user
* logged in with the specified session belongs.
*
* @param connection connection to use to get the user's shared groups.
* @return collection with the shared groups' name of the logged user.
*/
public static List<String> getSharedGroups(Connection connection) throws XMPPException {
// Discover the shared groups of the logged user
SharedGroupsInfo info = new SharedGroupsInfo();
info.setType(IQ.Type.GET);
// Create a packet collector to listen for a response.
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));
connection.sendPacket(info);
// Wait up to 5 seconds for a result.
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from the server.");
}
if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
return ((SharedGroupsInfo) result).getGroups();
}
示例14: InBandBytestreamManager
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Constructor.
*
* @param connection the XMPP connection
*/
private InBandBytestreamManager(Connection connection) {
this.connection = connection;
// register bytestream open packet listener
this.initiationListener = new InitiationListener(this);
this.connection.addPacketListener(this.initiationListener,
this.initiationListener.getFilter());
// register bytestream data packet listener
this.dataListener = new DataListener(this);
this.connection.addPacketListener(this.dataListener, this.dataListener.getFilter());
// register bytestream close packet listener
this.closeListener = new CloseListener(this);
this.connection.addPacketListener(this.closeListener, this.closeListener.getFilter());
}
示例15: InBandBytestreamSession
import org.jivesoftware.smack.Connection; //导入依赖的package包/类
/**
* Constructor.
*
* @param connection the XMPP connection
* @param byteStreamRequest the In-Band Bytestream open request for this session
* @param remoteJID JID of the remote peer
*/
protected InBandBytestreamSession(Connection connection, Open byteStreamRequest,
String remoteJID) {
this.connection = connection;
this.byteStreamRequest = byteStreamRequest;
this.remoteJID = remoteJID;
// initialize streams dependent to the uses stanza type
switch (byteStreamRequest.getStanza()) {
case IQ:
this.inputStream = new IQIBBInputStream();
this.outputStream = new IQIBBOutputStream();
break;
case MESSAGE:
this.inputStream = new MessageIBBInputStream();
this.outputStream = new MessageIBBOutputStream();
break;
}
}