I have programmed an XML Socket Server to communicate with Flash.
It doesn't print out the messages it has received from the flash until the server has been shut down. Any ideas?
The part with the problem:
The whole code:
It doesn't print out the messages it has received from the flash until the server has been shut down. Any ideas?
The part with the problem:
Code:
//Create streams BufferedReader data_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data_out = new PrintWriter(incoming.getOutputStream()); //Print sample welcome message data_out.println("<MESSAGE USER='John' TEXT='Hello, my name is John!' />" + EOF); data_out.flush(); boolean loopMAN = false; String line = null; while(null!=(line=data_in.readLine())) { //Print in server console System.out.println("Received message : " + line); //Write out to all clients connected data_out.write(line + EOF); data_out.flush(); } //Close the server data_out.close(); incoming.close(); s.close(); loopMAN = true; //Close the server if all clients disconnect if(loopMAN) { System.out.println("All clients disconnected!\nServer shut down."); System.exit(-1); }
Code:
// Name: XML Socket Server // Description: Communication with Macromedia Flash import java.net.*; import java.io.*; import java.util.*; public class ServerMain { public static void main(String[] args) { char EOF = (char)0x00; try { //Start server ServerSocket s = new ServerSocket(2000); System.out.println("Server running! Now accepting connections..."); Socket incoming = s.accept(); incoming.setTcpNoDelay(true); //Create streams BufferedReader data_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data_out = new PrintWriter(incoming.getOutputStream()); //Print sample welcome message data_out.println("<MESSAGE USER='John' TEXT='Hello, my name is John!' />" + EOF); data_out.flush(); boolean loopMAN = false; String line = null; while(null!=(line=data_in.readLine())) { //Print in server console System.out.println("Received message : " + line); //Write out to all clients connected data_out.write(line + EOF); data_out.flush(); } //Close the server data_out.close(); incoming.close(); s.close(); loopMAN = true; //Close the server if all clients disconnect if(loopMAN) { System.out.println("All clients disconnected!\nServer shut down."); System.exit(-1); } } catch (IOException e) { //Catch the exception System.out.println("Client Disconnected"); } } }