Java Code Examples for org.jivesoftware.smack.ConnectionConfiguration#setSecurityMode()
The following examples show how to use
org.jivesoftware.smack.ConnectionConfiguration#setSecurityMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 与服务器建立连接 * * @return */ public boolean connectServer() { ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort)); //设置安全模式 connConfig.setSecurityMode(SecurityMode.required); //设置SASL认证是否启用 connConfig.setSASLAuthenticationEnabled(false); //设置数据压缩是否启用 connConfig.setCompressionEnabled(false); //是否启用调试模式 connConfig.setDebuggerEnabled(true); /** 创建connection连接 */ XMPPConnection connection = new XMPPConnection(connConfig); this.setConnection(connection); try { // 连接到服务器 connection.connect(); L.i(LOGTAG, "XMPP connected successfully"); return true; } catch (XMPPException e) { L.e(LOGTAG, "XMPP connection failed", e); } return false; }
Example 2
Source File: LolChat.java From League-of-Legends-XMPP-Chat-Library with MIT License | 6 votes |
/** * 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(); }
Example 3
Source File: SmackGcmSenderChannel.java From arcusplatform with Apache License 2.0 | 5 votes |
/** * Connects to GCM Cloud Connection Server using the supplied credentials. * * @param senderId * Your GCM project number * @param apiKey * API Key of your project */ protected void connect(long senderId, String apiKey, int keepAliveInterval) throws XMPPException, IOException, SmackException { // Configure connection ConnectionConfiguration config = new ConnectionConfiguration(GcmServiceConstants.GCM_SERVER, GcmServiceConstants.GCM_PORT); config.setSecurityMode(SecurityMode.enabled); config.setReconnectionAllowed(true); config.setRosterLoadedAtLogin(false); config.setSendPresence(false); config.setSocketFactory(SSLSocketFactory.getDefault()); // Create connection object and initiate connection connection = new XMPPTCPConnection(config); pingManager = PingManager.getInstanceFor(connection); pingManager.setPingInterval(keepAliveInterval); pingManager.registerPingFailedListener(this); connection.connect(); // Register listener to log connection state events connection.addConnectionListener(new SmackLoggingConnectionListener()); // Handle incoming messages (delivery receipts and Google control messages) connection.addPacketListener(upstreamListener, new PacketTypeFilter(Message.class)); // Log in... connection.login(senderId + "@" + GcmServiceConstants.GCM_SERVER, apiKey); }
Example 4
Source File: XmppManager.java From androidpn-client with Apache License 2.0 | 5 votes |
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(); } }
Example 5
Source File: ClientConService.java From weixin with Apache License 2.0 | 5 votes |
public boolean login(String account, String password) { ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort)); //设置安全模式 connConfig.setSecurityMode(SecurityMode.required); //设置SASL认证是否启用 connConfig.setSASLAuthenticationEnabled(false); //设置数据压缩是否启用 connConfig.setCompressionEnabled(false); //是否启用调试模式 connConfig.setDebuggerEnabled(true); /** 创建connection连接 */ XMPPConnection connection = new XMPPConnection(connConfig); setConnection(connection); try { // 连接到服务器 connection.connect(); L.i(LOGTAG, "XMPP connected successfully"); //登陆 connection.login(account, password); /** 开启读写线程,并加入到管理类中 */ //ClientSendThread cst = new ClientSendThread(connection); //cst.start(); //ManageClientThread.addClientSendThread(account,cst); return true; } catch (XMPPException e) { L.e(LOGTAG, "XMPP connection failed", e); } return false; }
Example 6
Source File: MultiUserChatTest.java From Smack with Apache License 2.0 | 5 votes |
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(), getXMPPServiceDomain()); 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(); } }
Example 7
Source File: XmppClient.java From riotapi with Apache License 2.0 | 4 votes |
private static ConnectionConfiguration buildConnectionConfiguration(Shard shard) { ConnectionConfiguration connConf = new ConnectionConfiguration(shard.chatUrl, Shard.JABBER_PORT, "pvp.net"); connConf.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); connConf.setSocketFactory(SSLSocketFactory.getDefault()); return connConf; }
Example 8
Source File: XmppManager.java From android-demo-xmpp-androidpn with Apache License 2.0 | 4 votes |
public void run() { Log.i(LOGTAG, "ConnectTask.run()..."); if (!xmppManager.isConnected()) { //未连接到XMPP服务器 // 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 /** * 这个就是对于通信的xml文本进行解析的解析器,再把信息转换成IQ,这个相当于QQ的聊天信息 * 如果要用这个协议,其IQ的子类(NotificationIQ) * 和IQProvider的子类(NotificationIQProvider)要进行重写 */ ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider()); } catch (XMPPException e) { Log.e(LOGTAG, "XMPP connection failed", e); running = false; } //执行任务 xmppManager.runTask(); } else { Log.i(LOGTAG, "XMPP connected already"); //执行任务 xmppManager.runTask(); } }