Bonjour tous le monde, voici mon problème.
je doit préparé un application qui communique avec ces automates (3 automates) chaque automate a son adresse IP avec le même port d’écoute
automate 01 = "192.168.1.143"
automate 02 = "192.168.1.144"
automate 03 = "192.168.1.145"

pour quoi j'ai mis port d’écoute on rouge tout simplement parce que il son on mode Listen.

donc mon Application doit se connecté au (3) automate, puis envoyé une trame question pour recevoir une trame réponse de l'automate voulu.

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
Imports System.Net, System.Net.Sockets, System.IO, System.Threading
 
Module Module1
    Dim _sock As Socket
    Dim netStream As NetworkStream
    Dim Addy As String = "192.168.1.143"
    Dim port As Int32 = 1314
 
    Sub Main()
        'Console.WriteLine("Please enter a remote address to connect to")
        'Addy = Console.ReadLine()
        'Console.WriteLine("Please Enter a remote port to connect to")
        'port = CInt(Console.ReadLine())
        'Console.WriteLine("Please wait...")
        _sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        _sock.Connect(Addy, port)
 
        If _sock.Connected = True Then
            Console.WriteLine("Connected...")
            netStream = New NetworkStream(_sock)
            netStream.BeginRead(New Byte() {0}, 0, 0, AddressOf ReceiveData, Nothing)
        End If
        Do
            SendData(Console.ReadLine())
        Loop
        'Dim t As New Thread(AddressOf keepsub)
        't.Start()
    End Sub
 
    Sub SendData(ByVal data As String)
        Try
            Dim w As New StreamWriter(netStream)
            w.WriteLine(data)
            w.Flush()
        Catch ex As Exception
        End Try
    End Sub
 
    Sub ReceiveData(ByVal i As IAsyncResult)
        Try
            Dim r As New StreamReader(netStream)
            Console.WriteLine("Server: " & r.ReadLine)
            netStream.BeginRead(New Byte() {0}, 0, 0, AddressOf ReceiveData, Nothing)
        Catch ex As Exception
        End Try
    End Sub
 
    Sub keepsub()
        Do
            Console.ReadLine()
        Loop
    End Sub
 
End Module
avec un automate sa marche bien mais j'arrive pas a généralisé avec les autres,la ces on mode console et je voudrai le mettre sur un form.

je suis sur se sujet depuis 2 semaine non stop et la je bloc grave.

A l'aide SVP.