thanks Preeti Pathak,
My server writes an int then a
String to the socket, and my client reads them in the same order:
server:
ObjectOutputStream outi = new ObjectOutputStream(soc.getOutputStream());
PrintWriter outs = new PrintWriter(soc.getOutputStream(), true);
outi.writeInt(1234);
outi.flush();
outs.println("hello"); // autoflush
outi.close();
outs.close();
soc.close();
client:
ObjectInputStream ini = new ObjectInputStream(soc.getInputStream());
BufferedReader ins = new BufferedReader( new InputStreamReader(soc.getInputStream()) );
ini.readInt();
ins.readLine();
ini.close();
ins.close();
soc.close();
It works fine, but if i move ini.close(); just afert ini.readInt(); then ins.readLine(); throws me a "java.net.SocketException: Socket closed"
More strange: if the server writes a String first then a int, and the client reads them in the same order, then ini.readInt(); throws me a "java.io.EOFException"
What do you think about this?