Je me retrouve souvant avec cette exception, a force de changer mon code je me suis dit que je vais demander au forum. Je suis debutant avec les socket d'ou ma p-e mauvaise gestion de ceux-ci j'ai bô regarder sur google j'arrive pas a corriger mon code. merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
java.io.EOFException
	at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2325)
	at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2794)
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:801)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
	at Connexion.<init>(Connexion.java:23)
	at Serveur.run(Serveur.java:21)
	at java.lang.Thread.run(Thread.java:744)
Exception in thread "Thread-1" java.lang.NullPointerException
	at Connexion.run(Connexion.java:33)
	at java.lang.Thread.run(Thread.java:744)

code coté serveur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
public class Serveur implements Runnable {
 
	public static void main(String[] args) throws IOException {
		new Thread(new Serveur()).start();
	}
 
	public void run() {
		try {
			ServerSocket serverSocket = new ServerSocket(5555);
			Socket socket;
			ArrayList<Joueur> listJoueurs = new ArrayList<Joueur>();
 
			while (true) {
				socket = serverSocket.accept();
				new Connexion(socket, listJoueurs);
 
			}
		} catch (IOException e) {e.printStackTrace();}
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class Connexion implements Runnable {
 
	public Connexion (Socket socket, ArrayList<Joueur> listJoueurs) {
		this.listeJoueur = listJoueurs;
		try {
			this.in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
			this.out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
		} catch (IOException e) {e.printStackTrace();}
		this.joueur = new Joueur();
		this.start();
	}
 
	@Override
	public void run() {
		try {
			joueur.setNom((String) in.readObject());
			System.out.print(joueur.getNom());
			new Reception(joueur, in);
			joueur.startEmission(out);
			listeJoueur.add(joueur);
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
 
	public void start () {
		new Thread(this).start();
	}
 
	private Joueur joueur;
	private ObjectInputStream in;
	private ObjectOutputStream out;
	private ArrayList<Joueur> listeJoueur;
 
}
coté client

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public class Client {
 
	public static void main(String[] args) throws IOException {
		Joueur joueur = new Joueur("douney");
		Connexion connexion =  new Connexion(joueur);
		connexion.start();
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class Connexion implements Runnable {
 
	public Connexion (Joueur joueur) {
		this.joueur = joueur;
		if (joueur.getNom().equals(""))
			joueur.setNom();
		try {
			this.socket = new Socket(InetAddress.getLocalHost(), 5555);
			this.in = new ObjectInputStream(new BufferedInputStream(this.socket.getInputStream()));
			this.out = new ObjectOutputStream(new BufferedOutputStream(this.socket.getOutputStream()));	
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
	public void run () {
		try {
			this.out.writeObject(this.joueur.getNom());
			this.out.flush();
			new Reception(joueur, in);
			joueur.startEmission(out);			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
	public void start() {
		new Thread(this).start();
	}
 
 
	private Joueur joueur;
	private Socket socket;
	private ObjectOutputStream out;
	private ObjectInputStream in;
 
}