D
D
dmitriyprog2018-08-28 15:41:47
Java
dmitriyprog, 2018-08-28 15:41:47

How to fix an error when sending an object to the server?

Client side

private static Socket socket;

    public static void init() {
        try {
            socket =  new Socket("localhost",8888);
            handle();

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

    private static void handle() throws IOException {
        ObjectOutputStream dos =  new ObjectOutputStream(socket.getOutputStream());
        Definition def = new Definition("g", "gbv");
        System.out.println(def.hashCode());
        dos.writeObject(def);
        dos.flush();

    }

Server part
@Override
    public void run() {
        while (true) {
            try {
                ObjectInputStream dis = new ObjectInputStream(this.client.getInputStream());
                dis.readObject();


            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

Error
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully
I am writing with maven. The Definition class is written in one of the modules

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question