Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.XMPPConnection


    this.im = InstantMessagingModule.getAdapter();
  }

  public void run() {
    try {
      XMPPConnection connection = client.getConnection();
      connection.connect();
      connection.login(client.getChatUsername(), client.getPassword(), IMConfig.RESOURCE);
     
      if (log.isDebug()) {
        log.debug("Connection to IM server with username: "+client.getChatUsername());
      }
     
      client.setIsConnected(connection.isConnected() && connection.isAuthenticated());
      if (client.isConnected() && connection.isAuthenticated()) {
        im.getClientManager().addMessageListener(client.getUsername());
        im.getClientManager().addPresenceListener(client.getUsername());
        client.addSubscriptionListener();
       
        connection.addConnectionListener(new XMPPConnListener(client));
        client.setRoster(connection.getRoster());
        // subscription accept all = 0
        client.getRoster().setSubscriptionMode(SubscriptionMode.accept_all);
       
        String defaultStatus = client.getDefaultRosterStatus();
        if (defaultStatus.equals(Presence.Type.unavailable.toString())) client.sendPresenceUnavailable();
View Full Code Here


    //if group exists it will be renamed
    return createSharedGroup(groupId, displayName, null);
  }
 
  private boolean sendPacket(IQ packet) {
    XMPPConnection con = adminUser.getConnection();
    try {
      packet.setFrom(con.getUser());
      PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID()));
      con.sendPacket(packet);
      IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      collector.cancel();
     
      if (response == null) {
        log.error("Error while trying to create/delete group at IM server. Response was null! packet type: "+packet.getClass());
View Full Code Here

    // Debug enables a java window with all traffic between client
    // and server.
    XMPPConnection.DEBUG_ENABLED = false;
    // check if currently used im client is already connected
    // (reusing clients from previous session)
    connection = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());

    // connecting to server is done by thread pool
   
   
    if (Tracing.isDebugEnabled(this.getClass())) {
View Full Code Here

  public void closeConnection(boolean closeSynchronously) {
    // Set isConnected to false first since connection.close triggers an
    // XMPPConnListener.connectionClosed() event which would result in
    // in a cyclic call of this close method.
    isConnected = false;
    final XMPPConnection connectionToClose = connection;
    Runnable connectionCloseRunnable = new Runnable() {
      public void run() {
        try {
          connectionToClose.disconnect();
        } catch (RuntimeException e) {
          Tracing.logWarn("Error while trying to close instant messaging connection", e, InstantMessagingClient.class);
        }
      }
    };
View Full Code Here

    try {
      cb = new CyclicBuffer(bufferSize);

      // Create a connection to the XMPP server
      LogLog.debug("Stablishing connection with XMPP server");
      con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());
      // Most servers require you to login before performing other tasks
      LogLog.debug("About to login as [" + username + "/" + password
          + "]");
      con.connect();
      con.login(username, password);
View Full Code Here

      conConfig.setSASLAuthenticationEnabled(false);
      //the admin reconnects automatically upon server restart or failure but *not* on a resource conflict and a manual close of the connection
      conConfig.setReconnectionAllowed(true);
      //conConfig.setDebuggerEnabled(true);
      if (connection == null || !connection.isAuthenticated()) {
        connection = new XMPPConnection(conConfig);
        connection.connect();
        connection.addConnectionListener(new ConnectionListener() {
 
          public void connectionClosed() {
            log.warn("IM admin connection closed!");
View Full Code Here

  /**
   * @see org.olat.instantMessaging.syncservice.IInstantMessagingSessionCount#countSessions()
   */
  public int countSessions() {
    XMPPConnection con = adminUser.getConnection();
    if (con != null && con.isConnected()) {
      //TODO:gs may put in other thread???
      SessionCount response;
      try {
        IQ packet = new SessionCount();
        packet.setFrom(con.getUser());
        PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID()));
        con.sendPacket(packet);
        response = (SessionCount) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        collector.cancel();
        if (response == null) {
          log.warn("Error while trying to count sessions at IM server. Response was null!");
          return sessionCount;
View Full Code Here

    } //end of loop
    return entries;
  }
 
  private IQ sendPacket(IQ packet) {
    XMPPConnection con = adminUser.getConnection();
    try {
      packet.setFrom(con.getUser());
      PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID()));
      con.sendPacket(packet);
      IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      collector.cancel();
     
      if (response == null) {
        log.error("Error while trying to get all sessions IM server. Response was null!");
View Full Code Here

  /**
   * @see org.olat.instantMessaging.syncservice.IInstantMessagingSessionCount#countSessions()
   */
  public String getPluginVersion() {
    XMPPConnection con = adminUser.getConnection();
    if (con != null && con.isConnected()) {
      PluginVersion response;
      try {
        IQ packet = new PluginVersion();
        packet.setFrom(con.getUser());
        PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID()));
        //TODO:gs is sending packets over one connection thread save?
        con.sendPacket(packet);
        response = (PluginVersion) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        collector.cancel();
        if (response == null) {
          log.error("Error while trying to get version at IM server. Response was null!");
          return version;
View Full Code Here

            } else {
                config = new ConnectionConfiguration(uri.getHost(), port);

            }

            xmppConnection = new XMPPConnection(config);
            xmppConnection.connect();
            SASLAuthentication.supportSASLMechanism("PLAIN", 0);
            String[] credentials = authToken.split(":");

            xmppConnection.login(credentials[0], credentials[1], getID());
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.XMPPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.