Is there a working demo to send messages programmatically?

I’m able to connect to my server using a connect.jsp that I found on this board. When I use the sample code on the API’s doc to send a chat message to the server I get a Java error.

I was wondering is anyone would have a working code sample to send messages programmatically using smack.

I need to send chat messages from an application that I’m developing and I would greatly appreciate it if someone could post a working code sample that I could possibly use.

Jorge G

Hi Jorge,

Take a look at the Messaging Basics section of the Smack Documentation to see how to send a message.

Hope that helps,

Thanks Ryan.

I tried that before I made my initial post and the error I get on tomcat comes from MessageListener. The following code is the issue in my case:

new MessageListener() {

public void processMessage(Chat chat, Message message) {

System.out.println("Received message: " + message);


The error I get is:

Cannot refer to non-final variable out inside an inner class defined in a different method

Any help would be greatly appreciated.

Jorge Garifuna

Professional Web Developer

“Your Web Solution Partner”

Garinet Media Network, LLC.

811 Wilshire Blvd. Suite 1705

Los Angeles, CA 90017

that’s a java error, not a smack error. What it is saying is it cannot acces System.out.println. Which in itself is entirely bizarre. Perhaps you should post your entire code (given it is small) to figure this out in context. Because what you say is happening, should not be happening.


Thanks a million for your insight. Attached is the complete working demo, just in case someone else may need it.
Connect.jsp (2876 Bytes)

I’m not overly versed on jsp. But I don’t believe you are meant to use System.out.println() at all. you have a stream that you are usally passed in, in this case for you that would be out and you write to that and you you write to it ends on on the page the server returns.

try removing all the System’s and see what happens.


Thanks for the input. I just want to clarify that this issue has been resolved. The code on the attached file above works fine for my purposes.