Unable to send message to another client?

First, here’'s my code. For the GUI I am using JFrame.

try {

con= new XMPPConnection(“im102”,5222); //machine to connect to

con.login(user,pass);

chat=con.createChat(“phil@im167/Smack”);

textarea.append(“Connection Successful\nYou are logged in as “user”\n”);

chat.sendMessage(“Sup”);[/b]

}catch (XMPPException e) {

e.getXMPPError();

}

/code

The bold statement is never getting sent to my client, which is logged on via the Spark client. I do have a PacketListener call so I can receive messages from the Spark client. This is boggling my mind, any suggestions?

Also, attempting to create another connection to another user is making my gui freeze up. I have read that perhaps I need to spawn threads to deal with connections, can someone please post up an example? I have very little experience with threads and what resources they share with the main program.

Hi Phil,

you should use the Eclipse debugger or create a thread dump[/url] to get the cause of the lock. It may be a blocked AWT event queue.

LG

public class Test implements Runnable

{

private Thread bar;

private boolean exiting = false;

public Test()

{

System.out.println(“Test - enter”);

bar = new Thread(this);

bar.setDaemon(true);

bar.start();

System.out.println(“Test - exit”);

};

public void run()

{

while(true)

{

if ( exiting == true )

{

break;

};

System.out.print(".");

try

{

Thread.sleep(1000);

} catch (InterruptedException e)

{

System.out.println(“sleep interrupted”);

};

}

};

private void kill() throws InterruptedException

{

exiting = true;

bar.interrupt();

bar.join(1100);

};

public static void main(String[] args) throws Exception

{

System.out.println(“main - enter”);

Test foobar = new Test();

Thread.sleep(5000);

foobar.kill();

foobar = null;

System.out.println(“main - exit”);

};

};

/code

Just as a suggestion I would do the following:

chat = con.createChat(“phil@im167”)

/code

dropping the resource name.

I would then check the debugger window and check to see if the message packet is being sent from your client. If it is have a look at the “to” attribute and see what the JID address is.

Compare it with the fully qualified JID of the client logged into Spark.

I created a separate thread to handle connectiosn and now (almost) all is well!