(Mais um) Problema com Chat - EOFException

0 respostas
G

Olá!

procurei tanto no GUJ quanto na internet algo que pudesse resolver o meu problema. Porém tive que recorrer à vocês! Tenho Essa minha classe, que é o servidor que recebe os dados:

public class Server {
    private Socket server;

    private DataInputStream in = null;

    public static void main(String[] args) {
        Server sv = new Server();
        sv.establishConnection();
    }

    private void establishConnection() {
        try {
            ServerSocket server_socket = new ServerSocket(4360);
            server = server_socket.accept(); {
                while(true)
                {
                    try {
                        Thread.sleep(250);
                    } catch (InterruptedException ex) {

                    }
                    
                    in = new DataInputStream(server.getInputStream());
                    String msg = in.readUTF();
                    System.out.println(msg);
                }
            }

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void end()
    {
        try {
            server.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
E já na parte do GUI, há no método actionPerformed, o DataInputStream que envia os dados:
private void actionPerformed(java.awt.event.ActionEvent evt) {                                 
        Component c = (Component) evt.getSource();
        if(c == jButton1) {
            try {
                client = new Socket("127.0.0.1", 4360);

                out = new DataOutputStream(client.getOutputStream());
                if(jTextField1.getText().length() > 0) {
                    out.writeUTF(name + " diz: " + jTextField1.getText());
                }
            } catch (UnknownHostException ex) {

            } catch (IOException ex) {

            }
        }
    }
Porém estou recebendo a exceção EOFException. Segue o o console:
Gustavo diz: Olá!
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:323)
        at java.io.DataInputStream.readUTF(DataInputStream.java:572)
        at java.io.DataInputStream.readUTF(DataInputStream.java:547)
        at application.bin.Server.establishConnection(Server.java:25)
        at application.bin.Server.main(Server.java:15)

O que há de rrado com meu chat?

Criado 15 de dezembro de 2010
Respostas 0
Participantes 1