Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:58:53+00:00 2026-06-12T16:58:53+00:00

How do i receive a message from the server? I have the part where

  • 0

How do i receive a message from the server? I have the part where i could send message to the server but not receiving it from the server? How and what should it do? i am using xmpp as a transfer protocol

package com.example.xmpp.asmack;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

    public class XMPPAsATransportProtocol extends Activity implements OnClickListener {
        XMPPConnection conn;
        TextView output;
        final String HOST = "vps01.fit3140hack.org";
        final int PORT = 5222;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Log.d("xmppasatransportprotocol", "got to start");
            setContentView(R.layout.main);
            View createbutton = findViewById(R.id.button1);
            View messagebutton = findViewById(R.id.button2);
            View closebutton = findViewById(R.id.button3);
            output = (TextView) findViewById(R.id.textView2);
            Log.d("xmppasatransportprotocol", "got buttons");

            createbutton.setOnClickListener(this);
            messagebutton.setOnClickListener(this);
            closebutton.setOnClickListener(this);
        }

        private void sendMessage() throws XMPPException {
            Log.d("xmppasatransportprotocol", "sendmessage");
            Chat chat = conn.getChatManager().createChat("22686274test2@" + HOST, null);
            EditText message = (EditText)findViewById(R.id.editText1);
            chat.sendMessage(message.getText().toString());
        }
        private void openConnection() throws XMPPException {
            Log.i("xmppasatransportprotocol", "openconnection");
            ConnectionConfiguration config = new ConnectionConfiguration(HOST, PORT);
            config.setSASLAuthenticationEnabled(true);
            conn = new XMPPConnection(config);

            conn.connect();
            conn.login("22686274test1", "dummy");
        }
        private void closeConnection() {
            Log.i("xmppasatransportprotocol", "closeconnection");

            conn.disconnect();
        }

        public void onClick(View v) {
            try {
                switch(v.getId()) {
                    case R.id.button1:
                        openConnection();
                        Log.i("xmppasatransportprotocol", "Connected to " + HOST + ":" + PORT);
                        output.setText("Connected to " + HOST + ":" + PORT);
                        break;
                    case R.id.button2:
                        sendMessage();
                        Log.i("xmppasatransportprotocol", "message sent");
                        EditText message = (EditText)findViewById(R.id.editText1);
                        output.setText("Message sent:\n" + message.getText().toString());
                        break;
                    case R.id.button3:
                        closeConnection();
                        output.setText("Disconnected");
                        break;
                    default:    
                        throw new Exception("screwed up exception");
                }
            } catch (Exception e) {
                Log.d("xmppasatransportprotocol", "exception caught:" + e.getMessage());
                output.setText("Error: " + e.getMessage());
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:58:54+00:00Added an answer on June 12, 2026 at 4:58 pm
    1. Make sure you have the accounts you use there in the server.

    2. You need to listen for errors. Attach listeners to the respective connection publishers like conn.addConnectionCreationListener and such. For this, you need to implement interfaces like MessageListener, ConnectionCreationListener, org.jivesoftware.smack.ConnectionListener, PacketListener. When implementing these interfaces, the override connectionClosedOnError(Exception e) might give you an idea what’s wrong and in the overridden method processPacket(Packet packet) you should check for errors like this:

      if (packet.getError() != null) 
      {
          Exception e = new XMPPException(packet.getError())
          System.out.println(e);
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for
I have a email multi-part message which I am using to send failed message
I need a server to send and recieve XMPP messages from Android clients running
I would like to send the message from HelloWorldLayer, and receive it in ScoreLayer,
I have a TCP socket client receiving messages (data) from a server. messages are
The requirement of the TCP server: receive from each client and send result back
I have a AJAX client which must receive messages from server. Some messages from
I'm using C# on Windows Server 2008, and I want to receive a message
I have an iOS 5 pager application. Application can receive new message counter from
I have objects A and B that need to send and receive messages from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.