I am currently attempting to implement a chat program by using JFrame. I have the gui set up and everything, and when i had this in the main method it worked fine:
// try {
// con= new XMPPConnection(“im167”,5222);
// con.login(“test”, “test”);
//
// chat=con.createChat(“phil@im167/Smack”);
// textarea.append(“Connection established with phil@im167\n\n”);
//
// while(true) {
// Message message = chat.nextMessage();
// textarea.append(“phil@im167: “message.getBody()”\n”);
// }
//
// }catch (XMPPException e) {
// e.getXMPPError();
// System.out.println(“Failed”);
// }
Here is a pic of my gui for reference:
http://www.calpoly.edu/~pchoi/chat.JPG
Now when I click “update” it updates the list with users currently logged into the server. (For some reason it lists all users who are registered with the server and not only those who are online, but that’'s a bug for later!)
When I highlight a user, and then click connect, I want to be able to connect to the user. I have a method that is responsible for connecting users.
public void connectToUser(boolean firstConnect) throws IOException {
if (firstConnect == true) { //for initial connection to server
try {
con= new XMPPConnection(“im167”,5222);
con.login(“test”, “test”);
textarea.append(“Connection Successful\n”);
}catch (XMPPException e) {
e.getXMPPError();
}
}
else {
//Connecting to another user to chat
chat=con.createChat(“phil@im167/Smack”); //causes program to hang!!!
textarea.append(“Connection established with "userSelected"\n\n”);
while(true) {
Message message = chat.nextMessage();
textarea.append(userSelected*": “*message.getBody()+”\n");
}
}
}
This call:
chat=con.createChat(“phil@im167/Smack”);
causes my program to hang. Does anyone have any ideas on why it would cause my program to hang? I’'ve been stumped on this for hours!
I greatly appreciate your time and help!