Bonjour a vous,

voila je suis nouveau en c# j'essaye de développer un serveur multiThread voici mon code:

page progame.cs :

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
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
 
namespace serverMT
{
    class Program
    {
 
        public Socket socket {get; set;}
        Gestionnaire gestio = new Gestionnaire();
 
        public Program()
        {
 
            // creation du socket
            Socket ss = new Socket(
                AddressFamily.InterNetwork,
                SocketType.Stream,
                ProtocolType.Tcp);
 
            // creation d'un point d'accès
            IPEndPoint iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"),1234);
            ss.Bind(iep);
            ss.Listen(1);
 
 
            while (true)
            {
                Socket s = ss.Accept();
                Thread th = new Thread(gestio.Gestionnaire);
                th.Start(s);
            }
        }
 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
 
            new Program();
        }
    }
}

page gestionnaire.cs :

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
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
 
namespace serverMT
{
    class Gestionnaire
    {
        public void Gestionnaire(object o)  <----------------------------------------------------- problème ici (erreur -> Gestionnare : member names cannot be the same as their enclosing type)
        {
            Program pm = o as Program;
            NetworkStream ns = new NetworkStream(pm.socket);
            TextReader tr = new StreamReader(ns);
            TextWriter tw = new StreamWriter(ns);
        }
    }
}
en voyant ce code vous aurez devinez que en acceptant la connexion j ouvre un nouveau thread et je lui passe l objet socket je pense que le problème viens d ici.
merci a tous et a +