Echo Server

I’m trying to make a mini instant messanger using a java echo server and flash as the client.

I searched around google and found some source code for an echo server in java. I played around with the code and can’t seem to get it to work. I debugged it and it seems to stop when I read in from the incoming buffer. I can send it infinite messages and it still won’t read it in until I close out from the client program. Then the server recieves all of the messages typed and gives an error saying that the client closed out.

If anyone is experieced with java, I’d like some help in getting this to work
Here’s the source code for the java

If my question isn’t clear, or someone can help me and has AIM my screen name is FydusEx

A beforehand thanks…

Here’s the source code for the java server/client side + the flash client

import java.io.;
import java.net.
;
import java.util.*;

public class Server
{
public static void main(String args[])
{
try
{
ServerSocket s = new ServerSocket(9999);
for(;:wink:
{
System.out.println(“Server started. Waiting for connections…”);
Socket incoming = s.accept();
Client newThread = new Client(incoming);
newThread.start();
}
}
catch (Exception e)
{
System.out.println(“Connection lost”);
}
}
}

class Client extends Thread
{
protected Socket incoming;
protected BufferedReader in;
protected PrintWriter out;
protected String msg = new String();

public Client(Socket incoming)
{
    this.incoming = incoming;

    try
    {
        if (incoming != null)
        {
                in = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
                out = new PrintWriter(new OutputStreamWriter(incoming.getOutputStream()));
        }
    }
    catch (Exception e)
    {
        System.out.println("Error: " + e);
    }
}

public void run()
{
    System.out.println("New Client handler started.");
    out.println("Connected to Echo Server!");
    out.flush();
    boolean done = false;

    try
    {
        boolean quit = false;
        char EOF = (char)0x00;
        out.println("Type EXIT to quit." + EOF);
        out.flush();

        // Waits for the EXIT command
        do
        {
            //reads in line from incoming buffer
            msg = in.readLine();

            if(!msg.trim().equals("EXIT"))
            {
                out.println("Received: " + msg);
                out.flush();
                System.out.println("Received: " + msg);
            }
            else
                quit = true;
        }
        while(!quit);

        out.close();
        in.close();    
        incoming.close();
    }
    catch (IOException e)
    {
        System.out.println("Error");
    }
    System.out.println("Client thread stopped.");
    System.out.flush();
}

}

This is the Flash Client

mySocket = new XMLSocket();

mySocket.onConnect = function(success)
{
if (success)
display.text += “Server connection established!”;
else
display.text += “Server connection failed!”;
}

mySocket.onClose = function()
{
display.text = “Server connection lost”;
}

XMLSocket.prototype.onData = function(msg)
{
display.text = "MSG: " + msg;
display.text = "Message: " + msg;
}

//(server name, port)
mySocket.connect(“localhost”, 9999)

//— Handle button click --------------------------------------
function sendMsg()
{
if(msg.text != “”)
{
mySocket.send(msg.text);
trace(msg.text);
msg.text = “”;
}
}