Answer the question
In order to leave comments, you need to log in
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();
}
@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();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question