Bonsoir tout le monde,

J'ai un petit souci avec mon serveur Java. J'ai une application qui tourne et sert de serveur multithread. J'ai donc un premier thread qui sert à recevoir les connexions réseaux et qui se charge de créer à chaque nouvelle connexion un nouveau thread pour la communication avec ce client spécifique. Cependant après chaque requete envoyée par le client, on dirait que l'application serveur ne garde pas la meme connexion, c'est à dire qu'elle fait un nouveau "accept". Enfin voici le code :

Le thread principal :

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
public class ThreadServeur extends Thread
{
    private FrameServeur_ClientAlone frame_parent;
    private Properties prop;
    private MySocketMobileClient newConnection = null;
    private MySocketMobileServer ServerConnection = null;
 
 
    public ThreadServeur(FrameServeur_ClientAlone fr)
    {
        frame_parent = fr;
        prop= FileProperties.ChargeProperties("Configuration.properties");
        newConnection = new MySocketMobileClient();
        ServerConnection = new MySocketMobileServer();
    }
 
    @Override
    public void run()
    {
        System.out.println("debut connect serveur Client Alone");
        frame_parent.ajoutTexte("Création de la connexion Serveur Client Alone");
        ServerConnection.ConnexionServeur(Integer.parseInt(prop.getProperty("PORT_SERVEUR")));
        while(true)
        {
            System.out.println("Attente d'un client mobile");
            frame_parent.ajoutTexte("Attente d'un client mobile");
 
            newConnection = new MySocketMobileClient(ServerConnection.Accept());
            frame_parent.ajoutTexte("Nouveau client mobile arrivé !");
 
            System.out.println("Nouveau client mobile arrivé !");
 
            tcm = new ThreadClientMobile(newConnection,frame_parent);
            tcm.start();
        }
    }
Et le thread qui sert pour la communication avec le client :

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
public class ThreadClientMobile extends Thread
{
    private MySocketMobileClient ms;
 
    public ThreadClientMobile(MySocketMobileClient tempMS, FrameServeur_ClientAlone tempMaFrame)
    {
        ms = new MySocketMobileClient();
        ms = tempMS;
    }
 
    @Override
    public void run()
    {
        while (true)
        {
            recept = new String();
            ecritureCommentaire("Attente d'un recept client mobile.");
 
            recept = ms.ReceptM();
Et maintenant le code de socket proprement dit. Voici tout d'abord "MysocketMobileServer":

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
public class MySocketMobileServer {
 
    private Socket CSocket;
    private ServerSocket SSocket;
 
 
    public MySocketMobileServer()
    {
 
    }
 
    public Socket getS() {
        return CSocket;
    }
 
    public void setS(Socket s) {
        this.CSocket = s;
    }
 
    public ServerSocket getSSocket() {
        return SSocket;
    }
 
    public void setSSocket(ServerSocket SSocket) {
        this.SSocket = SSocket;
    }
 
    public void ConnexionServeur(int port)
    {
 
        try
        {
            SSocket = new ServerSocket(port);
        }
        catch (IOException ex)
        {
            Logger.getLogger(MySocket.class.getName()).log(Level.SEVERE, null, ex.getMessage());
        }
 
    }
 
    public Socket Accept()
    {
        try
        {
            CSocket = SSocket.accept();
            System.out.println("Accept réalisé");
            return CSocket;
        }
        catch (IOException ex)
        {
            Logger.getLogger(MySocket.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
 
 
    }
 
    public void DeconnexionClient()
    {
        try
        {
            CSocket.close();
        }
        catch (IOException ex)
        {
            Logger.getLogger(MySocket.class.getName()).log(Level.SEVERE, null, ex);
        }
 
    }
}
Et l'autre partie :

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
public class MySocketMobileClient {
 
    private Socket Socket;
    private DataInputStream dis;
    private DataOutputStream dos;
 
    public MySocketMobileClient(){
        Socket = null;
        dis = null;
        dos = null;
    }
 
    public MySocketMobileClient(Socket socket){
 
        this.Socket = socket;
        if(Socket != null){
            try
            {
                dos = new DataOutputStream (Socket.getOutputStream());
                dis = new DataInputStream (Socket.getInputStream());
 
            }
            catch(IOException e)
            {
 
            }
        }
    }
 
 
    public Socket getSocket() {
        return Socket;
    }
    public void setSocket(Socket Socket) {
        this.Socket = Socket;
    }
 
    public DataInputStream getDis() {
        return dis;
    }
 
    public void setDis(DataInputStream dis) {
        this.dis = dis;
    }
 
    public DataOutputStream getDos() {
        return dos;
    }
 
    public void setDos(DataOutputStream dos) {
        this.dos = dos;
    }
 
 
 
 
    public int ConnectionServeur (String NomServeur,int PortEcouteServeur)
    {
        try
        {
            Socket = new Socket(NomServeur,PortEcouteServeur);
            dos = new DataOutputStream (Socket.getOutputStream());
            dis = new DataInputStream (Socket.getInputStream());
        }
        catch(UnknownHostException e)
        {
            return 0;
        }
        catch(IOException e)
        {
            return 0;
        }
        return 1;
    }
 
    public boolean FermetureConnexion ()
    {
        try
        {
            dis.close();
            dos.close();
            Socket.close();
        }
        catch(IOException e)
        {
 
            return false;
        }
        return true;
    }
 
    public void EnvoiM (String msg){
 
        try
        {
            dos.writeUTF(msg);
            dos.flush();
        }
        catch(IOException e)
        {
        }
    }
 
    public String ReceptM ()
    {
        String reception = null;
        try 
        {
            reception = dis.readUTF();
            System.out.println("Message = " + reception);
        }
        catch (IOException ex)
        {
            Logger.getLogger(MySocketMobileClient.class.getName()).log(Level.SEVERE, null, ex);
        }
 
        return reception;
    }
}
Merci d'avance, ça fait des jours que je suis dessus et je ne trouve pas. C'est surement une bétise mais bon