Hi,
I have a 2 player, turn based game which uses DataInputStream and DataOutputStream to send and receive String and int messages to and from the server. I was looking for a way to receive the messages and paint the resulting changes while respecting the rule that all Swing jobs should only be done on the EDT, while receiving data should never be done on the EDT. I have found something that seems to work, but my question is really if it is the most efficient way and if there are other “standard” ways of doing this. This is what I am doing at the moment:
public void processMessage(String message){// Process messages sent by server
if(message.equals("do something")){
a = myReadInt();
b = myReadUTF();
}
Thank you in advance.
else if(message.equals("do something else")){
a = myReadInt();
b = myReadUTF();
}
String m = message;
try{
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
processMessageEDT(m, a, b);
}
});
}catch(Exception e){System.err.println("error");}
}