本文整理汇总了Java中org.jivesoftware.smack.Connection.sendPacket方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.sendPacket方法的具体用法?Java Connection.sendPacket怎么用?Java Connection.sendPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.Connection
的用法示例。
在下文中一共展示了Connection.sendPacket方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 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();
}
示例2: 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;
}
示例3: sendSearchForm
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
* Sends the filled out answer form to be sent and queried by the search service.
*
* @param con the current Connection.
* @param searchForm the <code>Form</code> to send for querying.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return ReportedData the data found from the query.
* @throws org.jivesoftware.smack.XMPPException
* thrown if a server error has occurred.
*/
public ReportedData sendSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.SET);
search.setTo(searchService);
search.addExtension(searchForm.getDataFormToSend());
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) {
return sendSimpleSearchForm(con, searchForm, searchService);
}
return ReportedData.getReportedDataFrom(response);
}
示例4: getLastActivity
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
* Retrieve the last activity of a particular jid.
* @param con the current Connection.
* @param jid the JID of the user.
* @return the LastActivity packet of the jid.
* @throws XMPPException thrown if a server error has occured.
* @deprecated This method only retreives the lapsed time since the last logout of a particular jid.
* Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity}
*/
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
LastActivity activity = new LastActivity();
jid = StringUtils.parseBareAddress(jid);
activity.setTo(jid);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
con.sendPacket(activity);
LastActivity response = (LastActivity) 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 response;
}
示例5: 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);
}
示例6: 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());
}
}
示例7: initiateIncomingStream
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException {
StreamInitiation response = createInitiationAccept(initiation,
getNamespaces());
// establish collector to await response
PacketCollector collector = connection
.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
connection.sendPacket(response);
Packet streamMethodInitiation = collector
.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (streamMethodInitiation == null) {
throw new XMPPException("No response from file transfer initiator");
}
return streamMethodInitiation;
}
示例8: 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();
}
示例9: getWorkgroups
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
AgentWorkgroups request = new AgentWorkgroups(agentJID);
request.setTo(serviceJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
// Send the request
connection.sendPacket(request);
AgentWorkgroups response = (AgentWorkgroups)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 response.getWorkgroups();
}
示例10: 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);
}
示例11: accept
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
* Accepts the In-Band Bytestream open request and returns the session to
* send/receive data.
*
* @return the session to send/receive data
* @throws XMPPException if stream is invalid.
*/
public InBandBytestreamSession accept() throws XMPPException {
Connection connection = this.manager.getConnection();
// create In-Band Bytestream session and store it
InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection,
this.byteStreamRequest, this.byteStreamRequest.getFrom());
this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession);
// acknowledge request
IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
connection.sendPacket(resultIQ);
return ibbSession;
}
示例12: doLoad
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
private void doLoad(Connection connection, String user) throws XMPPException {
setType(Type.GET);
PacketCollector collector = connection.createPacketCollector(
new PacketIDFilter(getPacketID()));
connection.sendPacket(this);
VCard result = null;
Packet packet = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (packet == null) {
String errorMessage = "Timeout getting VCard information";
throw new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.request_timeout, errorMessage));
}
if (packet.getError() != null) {
throw new XMPPException(packet.getError());
}
try {
result = (VCard) packet;
}
catch (ClassCastException e) {
System.out.println("No VCard for " + user);
return;
}
copyFieldsFrom(result);
}
示例13: updateLocalEntityCaps
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
* Updates the local user Entity Caps information with the data provided
*
* If we are connected and there was already a presence send, another
* presence is send to inform others about your new Entity Caps node string.
*
* @param discoverInfo
* the local users discover info (mostly the service discovery
* features)
* @param identityType
* the local users identity type
* @param identityName
* the local users identity name
* @param extendedInfo
* the local users extended info
*/
public void updateLocalEntityCaps() {
Connection connection = weakRefConnection.get();
DiscoverInfo discoverInfo = new DiscoverInfo();
discoverInfo.setType(IQ.Type.RESULT);
discoverInfo.setNode(getLocalNodeVer());
if (connection != null)
discoverInfo.setFrom(connection.getUser());
sdm.addDiscoverInfoTo(discoverInfo);
currentCapsVersion = generateVerificationString(discoverInfo, "sha-1");
addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo);
if (lastLocalCapsVersions.size() > 10) {
String oldCapsVersion = lastLocalCapsVersions.poll();
sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion);
}
lastLocalCapsVersions.add(currentCapsVersion);
caps.put(currentCapsVersion, discoverInfo);
if (connection != null)
jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1"));
final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() {
List<String> features = sdm.getFeaturesList();
List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList();
@Override
public List<Item> getNodeItems() {
return null;
}
@Override
public List<String> getNodeFeatures() {
return features;
}
@Override
public List<Identity> getNodeIdentities() {
return identities;
}
@Override
public List<PacketExtension> getNodePacketExtensions() {
return packetExtensions;
}
});
// Send an empty presence, and let the packet intercepter
// add a <c/> node to it.
// See http://xmpp.org/extensions/xep-0115.html#advertise
// We only send a presence packet if there was already one send
// to respect ConnectionConfiguration.isSendPresence()
if (connection != null && connection.isAuthenticated() && presenceSend) {
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
}
}
示例14: notifyService
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
public void notifyService(Connection con, String workgroup, String createdRoomName) {
NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName);
con.sendPacket(packet);
}