Mon serveur continue à obtenir cette erreur quand je lance le client:Pourquoi mon serveur et le client que j'ai codé en Java ne fonctionnent-ils pas?
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readInt(Unknown Source)
at java.io.ObjectInputStream.readInt(Unknown Source)
at MyServer.main(MyServer.java:10)
Voici le code du serveur:
import java.net.*;
import java.io.*;
public class MyServer{
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(40);
Socket clientSocket = serverSocket.accept();
ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
System.out.println(in.readInt());
serverSocket.close();
System.exit(0);
}
}
Et voici le code client:
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("localhost", 40);
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.writeInt(5);
socket.close();
System.exit(0);
}
}
il a travaillé. Je vous remercie!^_ ^ – William