Bonjour.
J'essaye de créer un pong en réseau et le réseau me pose un problème : les listener ne renvois plus rien ...
C'est à dire : J'ai un listener que voici :

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
public class PongMouseListener implements MouseListener, MouseMotionListener
{
	private Connection connect;
 
	public PongMouseListener(Connection connect)
	{
		super();
		this.connect = connect;
	}
 
	public void mouseClicked(MouseEvent e)
	{
		System.out.println("J'ai clic");
//		connect.talk("I Click\n");
	}
 
	public void mouseMoved(MouseEvent e)
	{
		System.out.println("Je bouge en :" + e.getX());
		connect.talk("Je bouge en :" + e.getX() + "\n");
	}
 
	public void mouseEntered(MouseEvent arg0){}
	public void mouseExited(MouseEvent arg0){}
	public void mousePressed(MouseEvent arg0){}
	public void mouseReleased(MouseEvent arg0){}
	public void mouseDragged(MouseEvent arg0){}
}
Et je peux bouger la souris et cliquer, rien ne s'écrit dans la console ...

J'ai l'impression que le problème est dû à la lecture par le socket, donc je vous fournit les codes de connection :

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
public class Connection extends Thread
{
	protected Socket			sock;
	protected static int		port		= 4321;
	protected BufferedReader	in;
	protected BufferedWriter	out;
	protected Obstacle			me;
	protected Obstacle			you;
	protected Ball				ball;
	protected PongPanel			pan;
	protected int				pointsP1	= 0;
	protected int				pointsP2	= 0;
 
	public void write(String s)
	{
		try
		{
			out.write(s + "\n");
			out.flush();
		}
		catch (IOException exception)
		{
			exception.printStackTrace();
		}
	}
 
	public String read()
	{
		try
		{
			return in.readLine();
		}
		catch (IOException exception)
		{
			exception.printStackTrace();
			return "";
		}
	}
 
	public void setPanel(PongPanel p)
	{
		pan = p;
	}
 
	public int getP1Pos()
	{
		return me.x;
	}
 
	public int getP2Pos()
	{
		return you.x;
	}
 
	public int[] getBallPos()
	{
		int[] v = { ball.x, ball.y };
		return v;
	}
 
	public int[] getPoints()
	{
		int[] v = { pointsP1, pointsP2 };
		return v;
	}
 
	public void talk(String s)
	{
	}
 
	public void run()
	{
		System.out.println("Thread running");
		try
		{
			while (true)
			{
				runActions();
				pan.graphicalRender();
				sleep(1000);
			}
		}
		catch (Exception exception)
		{
			exception.printStackTrace();
		}
	}
 
	public void runActions()
	{
	}
}
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
public class ConnectionServeur extends Connection
{
	private ServerSocket	serv;
	private boolean[]		differentsObjectKnowByTwoPlayer	= new boolean[4];
 
	public ConnectionServeur()
	{
		System.out.println("Vous êtes le serveur");
		serv = null;
		sock = null;
		try
		{
			System.out.println("Création du serveur");
			serv = new ServerSocket(port);
			System.out.println("En attente de connection du client sur l'IP \"" + serv.getLocalSocketAddress().toString() + "\" ...");
			sock = serv.accept();
			System.out.println("Le client s'est connecté !!!");
 
			System.out.println("Création des buffers ...");
			out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
			in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
			System.out.println("Buffers créés ...");
		}
		catch (IOException exception)
		{
			exception.printStackTrace();
		}
	}
 
	public void setElements(Obstacle playerOne, Obstacle playerTwo, Ball balle)
	{
		me = playerOne;
		you = playerTwo;
		ball = balle;
	}
 
	public void close()
	{
		try
		{
			sock.close();
			serv.close();
		}
		catch (IOException exception)
		{
			exception.printStackTrace();
		}
	}
 
	public void talk(String s)
	{
		if (s.startsWith("P2:"))
			talk(s.replace("P2:", ""), 1);
		else
			talk(s, 0);
	}
 
	public synchronized void talk(String s, int p)
	{
		if (s.compareTo("Ta Pos") == 0)
		{
			write("" + me.x);
			differentsObjectKnowByTwoPlayer[0] = true;
		}
		else if (s.compareTo("Ball Pos") == 0)
		{
			write(ball.x + ":" + ball.getInvertY());
			differentsObjectKnowByTwoPlayer[2] = true;
		}
		else if (s.compareTo("Points") == 0)
		{
			write(pointsP2 + ":" + pointsP1);
			differentsObjectKnowByTwoPlayer[3] = true;
		}
		else if (s.startsWith("Je bouge en :"))
		{
			if (p == 0)
				me.x = Integer.parseInt(s.split(":")[1]) - (me.w / 2);
			else
			{
				you.x = Integer.parseInt(s.split(":")[1]) - (you.w / 2);
				differentsObjectKnowByTwoPlayer[1] = true;
			}
		}
	}
 
	public boolean allObjectsKnowByTwoPlayer()
	{
		return (differentsObjectKnowByTwoPlayer[0] && differentsObjectKnowByTwoPlayer[1] && differentsObjectKnowByTwoPlayer[2] && differentsObjectKnowByTwoPlayer[3]);
	}
 
	public void allObjectsKnowByTwoPlayer(boolean b)
	{
		differentsObjectKnowByTwoPlayer[0] = b;
		differentsObjectKnowByTwoPlayer[1] = b;
		differentsObjectKnowByTwoPlayer[2] = b;
		differentsObjectKnowByTwoPlayer[3] = b;
	}
 
	public void runActions()
	{
		ArrayList<Obstacle> o = new ArrayList<Obstacle>();
		o.add(me);
		o.add(you);
		ball.move(o);
 
		int havePoint = ball.whoHavePoint();
		if (havePoint != 0)
		{
			if (havePoint == 1)
				pointsP1++;
			else
				pointsP2++;
			ball.replaceAtCenter();
		}
 
		while (!allObjectsKnowByTwoPlayer())
		{
			talk(read());
		}
		allObjectsKnowByTwoPlayer(false);
 
		pan.getInfosFromServerMe();
	}
}
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
public class ConnectionClient extends Connection
{
	private String	myText	= "P2:";
 
	public ConnectionClient()
	throws UnknownHostException,
	IOException
	{
		this("0.0.0.0");
	}
 
	public ConnectionClient(String host)
	throws UnknownHostException,
	IOException
	{
		System.out.println("Vous êtes le client");
		System.out.println("Connection au serveur ...");
		sock = new Socket(host, port);
		System.out.println("Vous êtes connecté !!!");
 
		System.out.println("Création des buffers ...");
		out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
		in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
		System.out.println("Buffers créés !!!");
	}
 
	public void close()
	{
		try
		{
			sock.close();
		}
		catch (IOException exception)
		{
			exception.printStackTrace();
		}
	}
 
	public void talk(String s)
	{
		if (s.startsWith("Je suis en :"))
			write(myText + s.replace("suis", "bouge"));
		else if (s.startsWith("Je bouge en :"))
			me.x = Integer.parseInt(s.split(":")[1]);
		else
			write(myText + s);
	}
 
	public int getP1Pos()
	{
		talk("Ma Pos");
		String s = read();
		return Integer.parseInt(s);
	}
 
	public int getP2Pos()
	{
		talk("Ta Pos");
		String s = read();
		return Integer.parseInt(s);
	}
 
	public int[] getBallPos()
	{
		talk("Ball Pos");
		String s[] = read().split(":");
		int[] v = { Integer.parseInt(s[0]), Integer.parseInt(s[1]) };
		return v;
	}
 
	public int[] getPoints()
	{
		talk("Points");
		String s[] = read().split(":");
		int[] v = { Integer.parseInt(s[0]), Integer.parseInt(s[1]) };
		return v;
	}
 
	public void runActions()
	{
		pan.getInfosFromServer();
	}
}
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 PongPanel extends JPanel
{
// Plein de code que je préfère vous épargner ...
	public void getInfosFromServer()
	{
		connect.talk("Je suis en :" + playerOne.x);
		playerTwo.x = connect.getP2Pos();
		int[] bp = connect.getBallPos();
		balle.x = bp[0];
		balle.y = bp[1];
		int[] pts = connect.getPoints();
		myPoints = pts[0];
		yourPoints = pts[1];
	}
 
	public void getInfosFromServerMe()
	{
		int[] pts = connect.getPoints();
		myPoints = pts[0];
		yourPoints = pts[1];
	}
}
Si nécessaire je peux rajouter la suite du code (400 lignes en plus ...)

Est-ce que quelqu'un pourrait m'aider à faire en sorte que les read() ou les listener se déroulent en même temps ou toute autre solution me permettant de bouger mes barres à la souris ?

Merci pour votre aide