当前位置: 首页>>代码示例>>Java>>正文


Java XMPPTCPConnection类代码示例

本文整理汇总了Java中org.jivesoftware.smack.tcp.XMPPTCPConnection的典型用法代码示例。如果您正苦于以下问题:Java XMPPTCPConnection类的具体用法?Java XMPPTCPConnection怎么用?Java XMPPTCPConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMPPTCPConnection类属于org.jivesoftware.smack.tcp包,在下文中一共展示了XMPPTCPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: XMPPConnector

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
/**
 * The constructor for the XMPP bot.
 *
 * @param host
 *            The server the bot should login.
 * @param port
 *            The hosts port.
 * @param login
 *            The bots login name.
 * @param password
 *            The bots login password.
 * @param resource
 *            The bots resource (i.e. Work or Home). Can be null.
 * @throws IllegalArgumentException
 *             Throws an {@link IllegalArgumentException} if some of the parameters are in an
 *             invalid format.
 */
public XMPPConnector(String host, String port, String login, String password, String resource)
        throws IllegalArgumentException {
    checkParameters(host, port, login, password, resource);
    int numericalPort = port == null ? DEFAULT_XMPP_PORT : Integer.parseInt(port);
    this.sender = login + "@" + host + "/" + resource;
    SmackConfiguration.DEBUG_ENABLED = Boolean.parseBoolean(ApplicationPropertyXmpp.DEBUG
            .getValue());
    ProviderManager.addExtensionProvider(AliasPacketExtension.ALIAS_ELEMENT_NAME,
            AliasPacketExtension.ALIAS_NAMESPACE, AliasPacketExtension.class);
    ConnectionConfiguration config = new ConnectionConfiguration(host, numericalPort);
    connection = new XMPPTCPConnection(config);
    connect(login, password, resource);
    sendPriorityPresence();
    if (connection.isConnected()) {
        LOG.info(ResourceBundleManager.instance().getText("xmpp.connection.started",
                Locale.ENGLISH));
        connection.addConnectionListener(new XMPPConnectionStatusLogger());
    } else {
        LOG.info("The XMPP connection wasn't established.");
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:39,代码来源:XMPPConnector.java

示例2: controlNotificationAlarm

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private void controlNotificationAlarm(boolean torchMode) {
	final XMPPTCPConnection connection = mXmppManager.getXmppConnection();
	final EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify();
	if (fullThingJid == null) return;

	SetBoolData setTorch = new SetBoolData(Constants.NOTIFICATION_ALARM, torchMode);
	IoTControlManager ioTControlManager = IoTControlManager.getInstanceFor(connection);

	LOGGER.info("Trying to control " + fullThingJid + " set torchMode=" + torchMode);

	try {
		final IoTSetResponse ioTSetResponse = ioTControlManager.setUsingIq(fullThingJid, setTorch);
	} catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
		mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not control thing: " + e, Toast.LENGTH_LONG).show());
		LOGGER.log(Level.SEVERE, "Could not set data", e);
	}
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:18,代码来源:XmppIotDataControl.java

示例3: connect

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
@Override
public void connect(XmppURI uri, String password) throws IOException, XMPPException, SmackException {
    this.disconnect();

    XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword(uri.getNode(), password)
            .setServiceName(uri.getDomain())
            .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
            .setDebuggerEnabled(true)
            .build();
    AbstractXMPPConnection connection = new XMPPTCPConnection(configuration);
    connection.connect();
    connection.login();
    // keep connection alive
    // when connection is idle it will run into timeout
    PingManager pingManager = PingManager.getInstanceFor(connection);
    pingManager.setPingInterval(60);
    pingManager.pingMyServer();

    this.connection = connection;
}
 
开发者ID:citlab,项目名称:Intercloud,代码行数:22,代码来源:XmppConnectionManager.java

示例4: initOMemoManager

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private OmemoManager initOMemoManager(XMPPTCPConnection conn, BareJid altUser) {
    BareJid user;

    if (conn.getUser() != null) {
        user = conn.getUser().asBareJid();
    } else {
        user = altUser;
    }

    mOmemoStore = OmemoService.getInstance().getOmemoStoreBackend();
    int defaultDeviceId = mOmemoStore.getDefaultDeviceId(user);

    if (defaultDeviceId < 1) {
        defaultDeviceId = OmemoManager.randomDeviceId();
        mOmemoStore.setDefaultDeviceId(user, defaultDeviceId);
    }

    return OmemoManager.getInstanceFor(conn, defaultDeviceId);
}
 
开发者ID:zom,项目名称:Zom-Android,代码行数:20,代码来源:Omemo.java

示例5: connect

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
public void connect(String hostname, int port, String username, String password) throws Exception {

    purgeTask("reconnect");

    this.hostname = hostname;
    this.serviceName = hostname;
    this.port = port;
    this.username = username;
    this.password = password;

    Builder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setUsernameAndPassword(username, password);
    builder.setServiceName(serviceName);
    builder.setServiceName(hostname);
    builder.setPort(port);
    builder.setSecurityMode(SecurityMode.disabled);
    builder.setDebuggerEnabled(true);

    XMPPTCPConnectionConfiguration config = builder.build();

    connection = new XMPPTCPConnection(config);
    connection.connect().login();

    roster = Roster.getInstanceFor(connection);
    chatManager = ChatManager.getInstanceFor(connection);

    roster.addRosterListener(this);

    isConnected = true;

    // not worth it - always empty right after connect
    // getContactList();

    broadcastState();
  }
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:36,代码来源:Xmpp.java

示例6: LolChat

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
/**
 * Represents a single connection to a League of Legends chatserver.
 * 
 * @param server
 *            The chatserver of the region you want to connect to
 * @param friendRequestPolicy
 *            Determines how new Friend requests are treated.
 * @param riotApiKey
 *            Your apiKey used to convert summonerId's to name. You can get
 *            your key here <a
 *            href="https://developer.riotgames.com/">developer
 *            .riotgames.com</a>
 * 
 * @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
 * @see LolChat#setFriendRequestListener(FriendRequestListener)
 */
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
		RiotApiKey riotApiKey) {
	this.friendRequestPolicy = friendRequestPolicy;
	this.server = server;
	if (riotApiKey != null && server.api != null) {
		this.riotApi = RiotApi.build(riotApiKey, server);
	}
	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
	final ConnectionConfiguration config = new ConnectionConfiguration(
			server.host, 5223, "pvp.net");
	config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
	config.setSocketFactory(SSLSocketFactory.getDefault());
	config.setCompressionEnabled(true);
	connection = new XMPPTCPConnection(config);

	addListeners();
}
 
开发者ID:TheHolyWaffle,项目名称:League-of-Legends-XMPP-Chat-Library,代码行数:34,代码来源:LolChat.java

示例7: XmppTransceiver

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private XmppTransceiver(XMPPTCPConnection connection, PacketFilter messageFilter) {
    this.connection = connection;
    PacketListener observablePacketListener = new PacketListener() {
        @Override
        public void processPacket(Packet packet) throws SmackException.NotConnectedException {
            pw.swordfish.sms.Message sms;
            try {
                sms = xmppToSms(Unsafe.<Message>cast(packet));
            } catch (MalformedSmsAddress ignored) {
                return;
            }
            for (Observer<pw.swordfish.sms.Message> observer : observers)
                observer.onNext(sms);
        }
    };
    this.connection.addPacketListener(observablePacketListener, messageFilter);
}
 
开发者ID:bdkoepke,项目名称:SmackPlus,代码行数:18,代码来源:XmppTransceiver.java

示例8: initGroupConnection

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private void initGroupConnection() {
    long currentUserId = CurrentUser.getInstance().getCurrentUserId();
    String currentUserPassword = CurrentUser.getInstance().getCurrentPassword();
    String jid = currentUserId + "-" + ApiConstants.APP_ID;
    groupChatConnection = new XMPPTCPConnection(
            jid, currentUserPassword, ApiConstants.MULTI_USERS_CHAT_ENDPOINT);
    groupChatConnection.addConnectionListener(this);
}
 
开发者ID:ukevgen,项目名称:BizareChat,代码行数:9,代码来源:QuickbloxGroupXmppConnection.java

示例9: initPrivateConnection

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private void initPrivateConnection() {
    long currentUserId = CurrentUser.getInstance().getCurrentUserId();
    String currentUserPassword = CurrentUser.getInstance().getCurrentPassword();
    String userName = currentUserId + "-" + ApiConstants.APP_ID;
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
    configBuilder.setUsernameAndPassword(userName, currentUserPassword);
    configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    configBuilder.setServiceName(ApiConstants.CHAT_END_POINT);
    configBuilder.setHost(ApiConstants.CHAT_END_POINT);
    configBuilder.setDebuggerEnabled(true);

    privateChatConnection = new XMPPTCPConnection(configBuilder.build());
    privateChatConnection.addConnectionListener(this);

    ReconnectionManager manager = ReconnectionManager.getInstanceFor(privateChatConnection);
    manager.enableAutomaticReconnection();
    manager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
    manager.setFixedDelay(15);

    ProviderManager.addExtensionProvider(Displayed.ELEMENT, Displayed.NAMESPACE, new Displayed.Provider());
    DisplayedManager.getInstanceFor(privateChatConnection).addDisplayedListener(
            (fromJid, toJid, receiptId, receipt) -> {
                messageService.get().processDisplayed(fromJid, toJid, receiptId, receipt);
            });

    ProviderManager.addExtensionProvider(Received.ELEMENT, Received.NAMESPACE, new Received.Provider());
    ReceivedManager.getInstanceFor(privateChatConnection).addReceivedListener(
            (fromJid, toJid, receiptId, receipt) -> {
                messageService.get().processReceived(fromJid, toJid, receiptId, receipt);
            });
}
 
开发者ID:ukevgen,项目名称:BizareChat,代码行数:32,代码来源:QuickbloxPrivateXmppConnection.java

示例10: createManagedConnection

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
public XMPPTCPConnection createManagedConnection(XMPPTCPConnectionConfiguration configuration) {
	XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
	ManagedXmppConnection managedConnection = new ManagedXmppConnection(connection);

	for (NewManagedConnectionListener newManagedConnectionListener : mNewConnectionListeners) {
		newManagedConnectionListener.newConnection(managedConnection);
	}

	synchronized (managedConnection) {
		mManagedConnections.put(connection, managedConnection);
	}

	return connection;
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:15,代码来源:AndroidSmackManager.java

示例11: disconnectConnections

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
void disconnectConnections() {
	forAllManagedConnections(new WithXmppConnection<XMPPTCPConnection>() {
		@Override
		public void withXmppConnection(XMPPTCPConnection connection, ManagedXmppConnection managedXmppConnection) {
			connection.disconnect();
		}
	});
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:9,代码来源:AndroidSmackManager.java

示例12: forAllManagedConnections

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
void forAllManagedConnections(WithXmppConnection<XMPPTCPConnection> withXmppConnection) {
	synchronized (mManagedConnections) {
		for (ManagedXmppConnection<XMPPTCPConnection> managedXmppConnection : mManagedConnections.values()) {
			final XMPPTCPConnection connection = managedXmppConnection.getConnection();
			if (connection == null) {
				mManagedConnections.remove(managedXmppConnection);
				continue;
			}
			withXmppConnection.withXmppConnection(connection, managedXmppConnection);
		}
	}
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:13,代码来源:AndroidSmackManager.java

示例13: claimButtonClicked

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private void claimButtonClicked(final Thing thing) {

		final XMPPTCPConnection connection = mXmppManger.getXmppConnection();
		if (connection == null) {
			showInGui("Not connection available");
			return;
		}

		if (!connection.isAuthenticated()) {
			showInGui("Connection not authenticated");
			return;
		}

		IoTDiscoveryManager ioTDiscoveryManager = IoTDiscoveryManager.getInstanceFor(connection);

		IoTClaimed iotClaimed;
		try {
			iotClaimed = ioTDiscoveryManager.claimThing(mRegistry, thing.getMetaTags(), true);
		} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
			showInGui("Could not claim because " + e);
			LOGGER.log(Level.WARNING, "Could not register", e);
			return;
		}

		EntityBareJid claimedJid = iotClaimed.getJid().asEntityBareJidIfPossible();
		if (claimedJid == null) {
			throw new IllegalStateException();
		}
		Settings settings = Settings.getInstance(this);
		settings.setClaimedJid(claimedJid);

		showInGui("Thing " + claimedJid + " claimed.");
		runOnUiThread(() -> {
			finish();
		});
	}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:37,代码来源:ClaimThingActivity.java

示例14: performReadOut

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
private void performReadOut() {
	XMPPTCPConnection connection = mXmppManager.getXmppConnection();
	EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify();
	if (fullThingJid == null) return;

	LOGGER.info("Requesting read out from " + fullThingJid);

	IoTDataManager iotDataManager = IoTDataManager.getInstanceFor(connection);
	final List<IoTFieldsExtension> res;
	try {
		res = iotDataManager.requestMomentaryValuesReadOut(fullThingJid);
	} catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException |InterruptedException e) {
		mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not perform read out: " + e, Toast.LENGTH_LONG).show());
		LOGGER.log(Level.WARNING, "Could not perform read out", e);
		return;
	}

	final List<? extends IoTDataField> dataFields = res.get(0).getNodes().get(0).getTimestampElements().get(0).getDataFields();

	mXmppManager.withMainActivity((ma) -> {
		ma.mIotSensorsLinearLayout.removeAllViews();
		for (IoTDataField field : dataFields) {
			IotSensorView iotSensorView = new IotSensorView(ma, field.getName(), field.getValueString());
			ma.mIotSensorsLinearLayout.addView(iotSensorView);
		}
	});
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:28,代码来源:XmppIotDataControl.java

示例15: login

import org.jivesoftware.smack.tcp.XMPPTCPConnection; //导入依赖的package包/类
public void login(String user, String pass, StatusItem status, String username)
            throws XMPPException, SmackException, IOException, InterruptedException {
        Log.i(TAG, "inside XMPP getlogin Method");
        long l = System.currentTimeMillis();
        XMPPTCPConnection connect = connect();
        if (connect.isAuthenticated()) {
            Log.i(TAG, "User already logged in");
            return;
        }

        Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));

        l = System.currentTimeMillis();
        connect.login(user, pass);
        Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));

        Log.i(TAG, "login step passed");

        Presence p = new Presence(Presence.Type.available);
        p.setMode(Presence.Mode.available);
        p.setPriority(24);
        p.setFrom(connect.getUser());
        if (status != null) {
            p.setStatus(status.toJSON());
        } else {
            p.setStatus(new StatusItem().toJSON());
        }
//        p.setTo("");
        VCard ownVCard = new VCard();
        ownVCard.load(connect);
        ownVCard.setNickName(username);
        ownVCard.save(connect);

        PingManager pingManager = PingManager.getInstanceFor(connect);
        pingManager.setPingInterval(150000);
        connect.sendPacket(p);


    }
 
开发者ID:saveendhiman,项目名称:XMPPSample_Studio,代码行数:40,代码来源:XMPP.java


注:本文中的org.jivesoftware.smack.tcp.XMPPTCPConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。