/** * 工厂模式获取连接对象 还没有连接服务器 * @param connectionTimeOut 连接超时的时间 * @param reconnectionAllowed 是否准许重连接 * @param isPresence 是否在线 * @param debugEnable 是否调试 * @param securityMode 安全模式 * @param connectionListener 连接监听器 * @return */ public static XMPPConnection createXMPPConnection(int connectionTimeOut, boolean reconnectionAllowed, boolean isPresence, boolean debugEnable, ConnectionConfiguration.SecurityMode securityMode, ConnectionListener connectionListener) { //设置是否开启DEBUG模式 XMPPConnection.DEBUG_ENABLED = debugEnable; //设置连接地址、端口 ConnectionConfiguration configuration = new ConnectionConfiguration(SERVERADDRESS, PORT); //设置服务器名称 configuration.setServiceName(SERVERNAME); //设置是否需要SAS验证 configuration.setSASLAuthenticationEnabled(false); //设置安全类型 configuration.setSecurityMode(securityMode); //设置用户状态 configuration.setSendPresence(isPresence); //设置是否准许重连接 configuration.setReconnectionAllowed(reconnectionAllowed); //实例化连接对象 XMPPConnection xmppConnection = new XMPPConnection(configuration); //添加连接监听器 if (connectionListener != null) { xmppConnection.addConnectionListener(connectionListener); } return xmppConnection; }
public XMPPTCPConnectionConfiguration.Builder getConnectionConfigBuilder() { if (!isBasicConfigurationDone()) return null; if (confBuilderCache == null) { XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder(); String password = getPassword(); builder.setUsernameAndPassword(getMyJid().getLocalpart(), password); builder.setXmppDomain(getMyJid().asDomainBareJid()); builder.setSecurityMode(ConnectionConfiguration.SecurityMode.required); SSLContext sc; try { sc = SSLContext.getInstance("TLS"); sc.init(null, new X509TrustManager[] { mMemorizingTrustManager }, new java.security.SecureRandom()); } catch (KeyManagementException | NoSuchAlgorithmException e) { throw new IllegalStateException(e); } builder.setCustomSSLContext(sc); confBuilderCache = builder; } return confBuilderCache; }
/** * 建立与服务器的持久连接 (必须仅能被getConnection()直接调用) * * @return boolean 成功。如成功连接服务器返回true,否则false */ private boolean connectToServer() { if (connection == null || !connection.isConnected()) { try { //配置连接 XMPPConnection.DEBUG_ENABLED = true; ConnectionConfiguration config = new ConnectionConfiguration(HOST, PORT, GROUP); config.setReconnectionAllowed(true); config.setSendPresence(false); //创建并连接 connection = new XMPPConnection(config); connection.connect(); if(!connection.isConnected()) throw new XMPPException(); return connection.isConnected(); } catch (XMPPException e) { e.printStackTrace(); connection = null; } } return false; }
public XMPPWithIQProtocol(String ipAddress, int port, String user, String password) throws XMPPException { // Connect: config = new ConnectionConfiguration(ipAddress, port); config.setSASLAuthenticationEnabled(false); config.setSecurityMode(SecurityMode.disabled); connection = new XMPPConnection(config); connection.connect(); // Login: connection.login(user, password, "root"); // Add IQ provider: ProviderManager.getInstance().addIQProvider("query", "iq:myOwn", new MyIQProvider()); }
/** * 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."); } }
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; }
@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; }
/** * Gets the XMPP connection. * * @return the XMPP connection */ public XMPPConnection getXMPPConnection() { if (this.xmpp == null) { ConnectionConfiguration config = new ConnectionConfiguration(serverConfigPrefsItem.getClusterHost(), serverConfigPrefsItem.getPort()); config.setSASLAuthenticationEnabled(false); config.setDebuggerEnabled(false); this.xmpp = new XMPPConnection(config); try { xmpp.connect(); xmpp.login(identity, serverConfigPrefsItem.getClusterPassword()); } catch (XMPPException e) { e.printStackTrace(); } } return xmpp; }
@PostConstruct void setup() { try { if (host.isEmpty() || user.isEmpty() || pass.isEmpty()) { log.info("disabling XMPP support; incomplete configuration"); conn = null; return; } ConnectionConfiguration cfg = new ConnectionConfiguration(host); cfg.setSendPresence(false); XMPPConnection c = new XMPPConnection(cfg); c.connect(); c.login(user, pass, resource); conn = c; log.info("connected to XMPP service <" + host + "> as user <" + user + ">"); } catch (Exception e) { log.info("failed to connect to XMPP server", e); } }
/** * 初始化连接 * @param loginConfig * @return */ public XMPPConnection init(IMConfig loginConfig) { Connection.DEBUG_ENABLED = false; ProviderManager pm = ProviderManager.getInstance(); configure(pm); connectionConfig = new ConnectionConfiguration( loginConfig.getXmppHost(), loginConfig.getXmppPort(), loginConfig.getXmppServiceName()); //connectionConfig.setSASLAuthenticationEnabled(false);// 不使用SASL验证,设置为false connectionConfig .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); // 允许自动连接 connectionConfig.setReconnectionAllowed(false); // 允许登陆成功后更新在线状态 connectionConfig.setSendPresence(true); // 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友 Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); connection = new XMPPConnection(connectionConfig); return connection; }
public static XMPPConnection connect(String host) throws XMPPException { ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222, "excalibur.org"); connectionConfiguration.setCompressionEnabled(false); connectionConfiguration.setSelfSignedCertificateEnabled(true); connectionConfiguration.setExpiredCertificatesCheckEnabled(false); connectionConfiguration.setDebuggerEnabled(false); connectionConfiguration.setSASLAuthenticationEnabled(true); connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); //XMPPConnection.DEBUG_ENABLED = false; XMPPConnection connection = new XMPPConnection(connectionConfiguration); connection.connect(); return connection; }
public ConnectionConfiguration build() { Preconditions.checkArgument(!Strings.isNullOrEmpty(this.host_) && !Strings.isNullOrEmpty(this.serviceName_)); ConnectionConfiguration configuration = new ConnectionConfiguration(host_, port_, serviceName_); configuration.setCompressionEnabled(this.compressionEnabled_); configuration.setSelfSignedCertificateEnabled(this.selfSignedCertificateEnabled_); configuration.setExpiredCertificatesCheckEnabled(this.expiredCertificatesCheckEnabled_); configuration.setSASLAuthenticationEnabled(this.saaslAuthenticationEnabled_); configuration.setSecurityMode(this.securityMode_); configuration.setRosterLoadedAtLogin(this.loadRosterAtLogin_); configuration.setSendPresence(this.sendPresence_); return configuration; }
/** * 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(); }
public ConnectionManager(Context context, ConnectionStatusCallback statusCallback, CommunicationManager communicationManager) { this.statusCallback = statusCallback; this.communicationManager = communicationManager; smack = SmackAndroid.init(context); SASLAuthentication.registerSASLMechanism(GTalkOAuthSASLMechanism.NAME, GTalkOAuthSASLMechanism.class); SASLAuthentication .supportSASLMechanism(GTalkOAuthSASLMechanism.NAME, 0); ConnectionConfiguration configuration = new ConnectionConfiguration( "talk.google.com", 5222, "gmail.com"); configuration.setSASLAuthenticationEnabled(true); connection = new XMPPConnection(configuration); }
private Connection makeXMPPConnection(String username, String password){ // Create the configuration for this new connection ConnectionConfiguration config = new ConnectionConfiguration("libraryh3lp.com", 5222); config.setCompressionEnabled(true); config.setSASLAuthenticationEnabled(true); // Create the connection and log in Connection con = new XMPPConnection(config); try { con.connect(); con.login(username, password); } catch (XMPPException e) { e.printStackTrace(); con = null; } return con; }
@Before public void setUp() throws Exception { KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(XMPPIntegrationTest.class.getResourceAsStream("/server.jks"), "secret".toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(keyStore); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom()); String port = AvailablePortFinder.readServerData("xmpp-port"); ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder() .setXmppDomain(JidCreate.domainBareFrom("apache.camel")) .setHostAddress(InetAddress.getLocalHost()) .setPort(Integer.parseInt(port)) .setCustomSSLContext(sslContext) .setHostnameVerifier((hostname, session) -> true) .build(); context.bind("customConnectionConfig", connectionConfig); }
/** * 通过主机名和端口号去对服务器进行连接和一些初始化 */ private void initConnect() { if (!isConnected()) { String connectionHost = mNotificationService.getHost(); int connectionPort = Integer.parseInt(mNotificationService .getPort()); ConnectionConfiguration connConfig = new ConnectionConfiguration( connectionHost, connectionPort); connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); mConnection = new XMPPConnection(connConfig); try { mConnection.connect(); ProviderManager.getInstance().addIQProvider(ELEMENT_NAME, NAME_SPACE, new NotificationIQProvider()); } catch (XMPPException e) { startReconnection(); } } }
public void init() throws XMPPException { SmackConfiguration.setPacketReplyTimeout(PACKET_REPLY_TIMEOUT); config = new ConnectionConfiguration(server, port); //SASLAuthentication.supportSASLMechanism("PLAIN"); //config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); //config.setSASLAuthenticationEnabled(true); //config.setReconnectionAllowed(true); //config.setRosterLoadedAtLogin(true); //config.setSendPresence(false); //config.setCompressionEnabled(true); connection = new XMPPConnection(config); connection.connect(); chatManager = connection.getChatManager(); packetListener = new XmppPacketListener(); }
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); }); }
/** * <b>function:</b> ��ʼSmack��openfire���������ӵĻ������� * * @author hoojo * @createDate 2012-6-25 ����04:06:42 */ public static void init() { try { // connection = new XMPPConnection(server); // connection.connect(); /** * 5222��openfire������Ĭ�ϵ�ͨ�Ŷ˿ڣ�����Ե�¼http://192.168.8.32:9090/ * ������Ա����̨�鿴�ͻ��˵��������˿� */ config = new ConnectionConfiguration(server, 5222); /** �Ƿ�����ѹ�� */ config.setCompressionEnabled(true); /** �Ƿ����ð�ȫ��֤ */ config.setSASLAuthenticationEnabled(false); /** �Ƿ����õ��� */ config.setDebuggerEnabled(false); // config.setReconnectionAllowed(true); // config.setRosterLoadedAtLogin(true); /** ����connection���� */ connection = new XMPPConnection(config); /** �������� */ connection.connect(); } catch (XMPPException e) { e.printStackTrace(); } // fail(connection); // fail(connection.getConnectionID()); }
public MessageSender build() { final ConnectionConfiguration configuration = new ConnectionConfiguration( this.host, this.port, this.serviceName == null ? this.host : this.serviceName); configuration.setSASLAuthenticationEnabled(this.isSASLAuthenticationEnabled); configuration.setSendPresence(this.isSendPresence); configuration.setSecurityMode(this.securityMode.getConfigurationValue()); return new MessageSender( configuration, this.userName, this.password, this.saslAuthenticationTypes, this.receivers); }
public MessageSender( final ConnectionConfiguration configuration, final String userName, final String password, final List<String> saslAuthenticationTypes, final List<String> bodies) { this.configuration = configuration; this.userName = userName; this.password = password; this.bodies = bodies; this.saslAuthenticationTypes = Collections.unmodifiableList(saslAuthenticationTypes); }
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException { XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder(); builder.setHost(HOST1); builder.setPort(PORT); builder.setCompressionEnabled(false); builder.setDebuggerEnabled(true); builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); builder.setSendPresence(true); if (Build.VERSION.SDK_INT >= 14) { builder.setKeystoreType("AndroidCAStore"); // config.setTruststorePassword(null); builder.setKeystorePath(null); } else { builder.setKeystoreType("BKS"); String str = System.getProperty("javax.net.ssl.trustStore"); if (str == null) { str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security" + File.separator + "cacerts.bks"; } builder.setKeystorePath(str); } DomainBareJid serviceName = JidCreate.domainBareFrom(HOST); builder.setServiceName(serviceName); return builder.build(); }
public void run() { Log.i(LOGTAG, "ConnectTask.run()..."); boolean connected = false; if (!xmppManager.isConnected()) { // Create the configuration for this new connection ConnectionConfiguration connConfig = new ConnectionConfiguration( xmppHost, xmppPort); // connConfig.setSecurityMode(SecurityMode.disabled); connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); XMPPConnection connection = new XMPPConnection(connConfig); xmppManager.setConnection(connection); try { // Connect to the server connection.connect(); Log.i(LOGTAG, "XMPP connected successfully"); // packet provider ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider()); connected = true; } catch (XMPPException e) { Log.e(LOGTAG, "XMPP connection failed", e); } if (connected) { xmppManager.runTask(); } } else { Log.i(LOGTAG, "XMPP connected already"); xmppManager.runTask(); } }
@Override protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException { StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE); if (startTlsFeature != null) { if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) { notifyConnectionError(new SecurityRequiredByServerException()); return; } // 发送StartTLS的封包 // 让我们进入TLS链接 if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) { send(new StartTls()); } } // If TLS is required but the server doesn't offer it, disconnect // from the server and throw an error. First check if we've already negotiated TLS // and are secure, however (features get parsed a second time after TLS is established). if (!isSecureConnection() && startTlsFeature == null && getConfiguration().getSecurityMode() == SecurityMode.required) { throw new SecurityRequiredByClientException(); } if (getSASLAuthentication().authenticationSuccessful()) { // If we have received features after the SASL has been successfully completed, then we // have also *maybe* received, as it is an optional feature, the compression feature // from the server. maybeCompressFeaturesReceived.reportSuccess(); } }
/** * Creates a new XMPPTCPConnection using the connection preferences. This is useful when * not using a connection from the connection pool in a test case. * * @return a new XMPP connection. */ protected XMPPTCPConnection createConnection() { // Create the configuration for this new connection ConnectionConfiguration config = new ConnectionConfiguration(host, port); config.setCompressionEnabled(compressionEnabled); config.setSendPresence(sendInitialPresence()); if (getSocketFactory() == null) { config.setSocketFactory(getSocketFactory()); } return new XMPPTCPConnection(config); }
public void testAnonymousParticipant() { try { // Anonymous user joins the new room ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(getHost(), getPort(), getServiceName()); XMPPTCPConnection anonConnection = new XMPPConnection(connectionConfiguration); anonConnection.connect(); anonConnection.loginAnonymously(); MultiUserChat muc2 = new MultiUserChat(anonConnection, room); muc2.join("testbot2"); Thread.sleep(400); // User1 checks the presence of Anonymous user in the room Presence presence = muc.getOccupantPresence(room + "/testbot2"); assertNotNull("Presence of user2 in room is missing", presence); assertTrue( "Presence mode of user2 is wrong", presence.getMode() == null || presence.getMode() == Presence.Mode.available); // Anonymous user leaves the room muc2.leave(); anonConnection.disconnect(); Thread.sleep(250); // User1 checks the presence of Anonymous user in the room presence = muc.getOccupantPresence(room + "/testbot2"); assertNull("Presence of participant testbotII still exists", presence); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
public void testManyResources() throws Exception { // Create 5 more connections for user2 XMPPTCPConnection[] conns = new XMPPConnection[5]; for (int i = 0; i < conns.length; i++) { ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(getHost(), getPort(), getServiceName()); connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); conns[i] = new XMPPTCPConnection(connectionConfiguration); conns[i].connect(); conns[i].login(getUsername(1), getPassword(1), "resource-" + i); Thread.sleep(20); } // Join the 5 connections to the same room MultiUserChat[] mucs = new MultiUserChat[5]; for (int i = 0; i < mucs.length; i++) { mucs[i] = new MultiUserChat(conns[i], room); mucs[i].join("resource-" + i); } Thread.sleep(200); // Each connection has something to say for (int i = 0; i < mucs.length; i++) { mucs[i].sendMessage("I'm resource-" + i); } Thread.sleep(200); // Each connection leaves the room and closes the connection for (MultiUserChat muc1 : mucs) { muc1.leave(); } Thread.sleep(200); for (int i = 0; i < mucs.length; i++) { conns[i].disconnect(); } }
private XMPPTCPConnection createConnectionInternal() { if (connectionConfig != null) { return new XMPPTCPConnection(connectionConfig); } if (port == 0) { port = 5222; } String sName = getServiceName() == null ? host : getServiceName(); ConnectionConfiguration conf = new ConnectionConfiguration(host, port, sName); return new XMPPTCPConnection(conf); }
public XMPPConnection init(LoginConfig loginConfig) { Connection.DEBUG_ENABLED = false; ProviderManager pm = ProviderManager.getInstance(); configure(pm); connectionConfig = new ConnectionConfiguration( loginConfig.getXmppHost(), loginConfig.getXmppPort(), loginConfig.getXmppServiceName()); try { Class.forName("org.jivesoftware.smackx.ServiceDiscoveryManager", true, XmppConnectionManager.class.getClassLoader()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } /// ServiceDiscoveryManager discoManager = new ServiceDiscoveryManager(connection); connectionConfig.setSASLAuthenticationEnabled(false);// ��ʹ��SASL��֤������Ϊfalse connectionConfig .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); // �����Զ����� connectionConfig.setReconnectionAllowed(false); // �����½�ɹ����������״̬ connectionConfig.setSendPresence(true); // connectionConfig.setSendPresence(false); // �յ����������manual��ʾ��Ҫ����ͬ��,accept_all��ʾ����ͬ���Զ�Ϊ���� Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); connection = new XMPPConnection(connectionConfig); return connection; }
public void LogIn(String usrnme, String pwd) throws XMPPException { ConnectionConfiguration cnfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); conn = new XMPPConnection(cnfig); conn.connect(); conn.login(usrnme, pwd); }
public void run() { Log.i(LOGTAG, "ConnectTask.run()..."); if (!xmppManager.isConnected()) { // Create the configuration for this new connection ConnectionConfiguration connConfig = new ConnectionConfiguration( xmppHost, xmppPort); // connConfig.setSecurityMode(SecurityMode.disabled); connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); XMPPConnection connection = new XMPPConnection(connConfig); xmppManager.setConnection(connection); try { // Connect to the server connection.connect(); Log.i(LOGTAG, "XMPP connected successfully"); // packet provider ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider()); } catch (XMPPException e) { Log.e(LOGTAG, "XMPP connection failed", e); } xmppManager.runTask(); } else { Log.i(LOGTAG, "XMPP connected already"); xmppManager.runTask(); } }
/** * Initializes the XMPP Client. Sets the time-out-limit whilst waiting for XMPP-replies from * server. Sets the XMPP configurations to connect to the server and creates the * XMPPConnection object used for connecting and Logging-In. */ private void initXMPPClient() { log.info(String.format("Initializing connection to XMPP Server at %1$s via port " + "%2$d......", server, port)); SmackConfiguration.setPacketReplyTimeout(timeoutInterval); config = new ConnectionConfiguration(server, port); // TODO:: Need to enable SASL-Authentication appropriately config.setSASLAuthenticationEnabled(false); config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); connection = new XMPPConnection(config); }
public void run() { Log.i(LOGTAG, "ConnectTask.run()..."); if (!xmppManager.isConnected()) { // Create the configuration for this new connection ConnectionConfiguration connConfig = new ConnectionConfiguration( xmppHost, xmppPort); // connConfig.setSecurityMode(SecurityMode.disabled); connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); XMPPConnection connection = new XMPPConnection(connConfig); xmppManager.setConnection(connection); try { // Connect to the server connection.connect(); Log.i(LOGTAG, "XMPP connected successfully"); // packet provider ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider()); xmppManager.runTask(); } catch (XMPPException e) { Log.e(LOGTAG, "XMPP connection failed", e); xmppManager.dropTask(2); xmppManager.startReconnectionThread(); xmppManager.runTask(); } } else { Log.i(LOGTAG, "XMPP connected already"); xmppManager.runTask(); } }
public void setup() { this.configBuilder = XMPPTCPConnectionConfiguration.builder(); this.configBuilder.setUsernameAndPassword(XMPPConnectionHandler.username, XMPPConnectionHandler.password); this.configBuilder.setResource(XMPPConnectionHandler.resource); this.configBuilder.setServiceName(XMPPConnectionHandler.service); this.configBuilder.setHost(XMPPConnectionHandler.host); this.configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); this.connection = new XMPPTCPConnection(this.configBuilder.build()); }
public void run() { if (!xmppManager.isConnected()) { // Create the configuration for this new connection ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, xmppPort); // connConfig.setSecurityMode(SecurityMode.disabled); // connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); connConfig.setSecurityMode(SecurityMode.disabled); XMPPConnection connection = new XMPPConnection(connConfig); xmppManager.setConnection(connection); try { // Connect to the server connection.connect(); // packet provider ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider()); reconnection.waiting = 0; reconnection.needWork.set(false); } catch (XMPPException e) { e.printStackTrace(); } xmppManager.runTask(); } else { xmppManager.runTask(); } }
/** * Initializes the XMPP Client. Sets the time-out-limit whilst waiting for XMPP-replies from * server. Sets the XMPP configurations to connect to the server and creates the * XMPPConnection object used for connecting and Logging-In. */ private void initXMPPClient() { log.info(String.format("Initializing connection to XMPP Server at %1$s via port " + "%2$d.", server, port)); SmackConfiguration.setPacketReplyTimeout(timeoutInterval); config = new ConnectionConfiguration(server, port); // TODO:: Need to enable SASL-Authentication appropriately config.setSASLAuthenticationEnabled(false); config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); connection = new XMPPConnection(config); }