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
| Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Public Class _Default
Inherits Page
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
Public Class ThreadManager
Public MonThread As Thread
Public Mess As Byte()
Public Envoi As Integer
Public MonEP As IPEndPoint
Public MonSocketClient As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
AGE_connexion()
Public Sub AGE_connexion()
Try
MonEP = New IPEndPoint(IPAddress.Parse("127.0.0.1"), 45435)
MonSocketClient.Connect(MonEP)
Return
Catch ex As Exception
Return
End Try
End Sub
Public Sub envoyer_message(message)
Mess = Encoding.UTF8.GetBytes(message)
Envoi = MonSocketClient.Send(Mess)
End Sub
Public Sub lecture()
MonThread = New Thread(AddressOf ThreadLecture)
MonThread.Start()
End Sub
Public Sub ThreadLecture()
While (MonSocketClient.Connected)
Dim Bytes(255) As Byte
Dim Recu As Integer
Try
Recu = MonSocketClient.Receive(Bytes)
Catch ex As Exception
MsgBox("Connexion perdue, arrêt de la réception des données ...", 1)
End Try
Dim Message As String
Message = System.Text.Encoding.UTF8.GetString(Bytes)
Message = Message.Substring(0, Recu)
MsgBox(Message)
End While
End Sub
End Class
End Class |
Partager