Bonjour,

Je suis s�r que le probl�me n'est absolument pas dur mais �a fait des journ�es que je recherche la solution. J'ai trouv� du code sur internet pour pouvoir cr�er une socket Asynchrone (qui fonctionnait tr�s bien) mais lorsque j'ai voulut la transformer en classe elle ne fonctionne plus, le programme passe bien par les bonnes fonctions d'initialisations et tout mais �a ne fonctionne plus. Voici mon code :

J'ai fais mon code sous ce sch�ma :


Le code cot� server :
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
Code C# :
 
protected void Button1_Click(object sender, EventArgs e)
{
 
    /*NetworkStream NS;
    StreamReader SR;
    StreamWriter SW;
 
    string host;
    int port;
 
    host = "10.10.62.22";
    port = 11000;
 
    TcpClient tcp_client = new TcpClient(host, port);
 
    NS = tcp_client.GetStream();
 
    SW = new StreamWriter(NS);
    SW.WriteLine("Boiler");
    SW.Flush();
 
    SR = new StreamReader(NS);
    Label_message_recut.Text = SR.ReadLine();*/
 
 
      Test() ; 
 
}
 
public void Test()
{
    string[] TempString;
    Domain_server.DomainServiceClasse ObjectDomainServiceClasse= new Domain_server.DomainServiceClasse();
    ObjectDomainServiceClasse.Connection(11000);
    ObjectDomainServiceClasse.SendData("Boiler");
 
    TempString = ObjectDomainServiceClasse.ReceiveData() ;
    Label_DeviceName.Text = TempString[0];
    Label_DeviceConsumption.Text = TempString[1];
    Label_DeviceState.Text = TempString[3];
 
    ObjectDomainServiceClasse.Deconnection();
}
Voici le code au niveau de mon Domain Service Class
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
Code C# :
 
namespace Final_page_second_project.Domain_server
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    //Contient les points de terminaison pris en charge dans les service RIA
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
 
 
    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
        public class DomainServiceClasse : DomainService
            {
                Domain_server.SocketClass SocketTransmition = new Domain_server.SocketClass();
 
                public void Connection(int pPort)
                {
                    SocketTransmition.connection(pPort);
                }
 
                public void Deconnection()
                {
                    SocketTransmition.deconnection();
                }
 
                public void SendData(string pMessage)
                {
                    SocketTransmition.sendData(pMessage);
                 }
 
                public string[] ReceiveData()
                {
                    return SocketTransmition.receivedData();
                }
 
            }  
 
 
    }


Et un fichier contenant l'impl�mentation de ma classe:
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
 
Code C# :
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
    //For NetworkStream
    using System.Net.Sockets;
    //For streamReader and StreamWriter
    using System.IO;
using System.Net;
using System.Text;
 
 
namespace Final_page_second_project.Domain_server
{
 
 
    public class SocketClass
    {
        private byte[] bytes;
        private IPHostEntry ipHostInfo;
        private IPAddress ipAddress;
        private IPEndPoint remoteEP;
        private int Port;
        private Socket socket;
        private byte[] messageToSend;
        private int byteToSend;
        private string dataReceived;
        private char[] charSeparator;
        private string[] dataSplitted;
 
        //Constructor
        public SocketClass()
        {
            bytes = new byte[1024];
            ipHostInfo = Dns.Resolve(Dns.GetHostName());
            ipAddress = ipHostInfo.AddressList[0];
 
            socket = new Socket(
                                                    AddressFamily.InterNetwork,
                                                    SocketType.Stream,
                                                    ProtocolType.Tcp
                                                    );
            Port = 11000;
            messageToSend = null;
            byteToSend = 0;
            dataReceived = "";
            charSeparator = null;
            dataSplitted = null;
        }
 
        public void LaunchProgram()
        {
            try
            {
 
            }
            catch (ArgumentNullException ane) {ane.ToString();}
            catch (SocketException se) {se.ToString();}
            catch (Exception e) {e.ToString();}
        }
 
        //Handle connection to server (other program)
        public void connection(int pPort)
        {
            remoteEP = new IPEndPoint(ipAddress, pPort);
            socket.Connect(remoteEP);           
        }
 
        //Disconnect the server from remote program
        public void deconnection()
        {
           socket.Shutdown(SocketShutdown.Both);
           socket.Close();
        }
 
        public void sendData(string pMessage)
        {
            // Encode the data string into a byte array.
            messageToSend = Encoding.ASCII.GetBytes(pMessage);
 
            // Send the data through the socket.
            byteToSend = socket.Send(messageToSend);
        }
 
        public string[] receivedData()
        {
            int byteRec = socket.Receive(bytes);
 
            charSeparator = new char[] { '+' };
            // Receive the response from the remote device.
            dataReceived = Encoding.ASCII.GetString(bytes, 0, byteRec);              
            dataSplitted = dataReceived.Split(charSeparator, StringSplitOptions.None);
 
            return dataSplitted ;
        }
 
 
     }//End of class
 
 
}//End of namespace


S'il vous plait �a fait des journ�es que je suis sur ce probl�me ^^

Merci � tout le monde. Bonne journ�e.