Code:
public class Client {
static final String IP = "etwas";
static final int PORT = 1111;
public static void main(String[] args) throws IOException, ClassNotFoundException {
Socket client = null;
try {
client = new Socket(IP, PORT);
} catch (IOException e) {
System.out.println("Error connection to server:" + e);
}
ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
System.out.println("Sending request...");
out.writeObject("bla bla".getBytes());
out.writeObject(-1);
ObjectInputStream in = new ObjectInputStream(client.getInputStream());
String message = (String) in.readObject();
System.out.println(message);
out.writeObject("bla bla".getBytes());
out.writeObject(-1);
in.close();
out.close();
client.close();
}
Hallo Leute, ich habe immer diese Exception:
Exception in thread "main" java.io.StreamCorruptedException: invalid stream header: 54696D65
at java.base/java.ibjectInputStream.readStreamHeader(ObjectInputStream.java:877)
at java.base/java.ibjectInputStream.<init>(ObjectInputStream.java:350)
at ChatBoard.Client.main(Client.java:108)
Was soll ich mit ObjectInputStream tun? Danke!