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
|
Public Class cls_communication_flux
Dim c_buffer(1024) As Byte
Dim c_message As StringBuilder = New StringBuilder()
Private c_tcpclient As TcpClient
Private c_flux As Net.Sockets.NetworkStream
Sub New(ByVal p_tcpclient As TcpClient)
c_tcpclient = p_tcpclient
c_flux = c_tcpclient.GetStream
End Sub
Function LireFlux() As String
If c_flux.CanRead Then
Dim numberOfBytesRead As Integer = 0
Do
numberOfBytesRead = c_flux.Read(c_buffer, 0, c_buffer.Length)
c_message.AppendFormat("{0}", Encoding.ASCII.GetString(c_buffer, 0, numberOfBytesRead))
Loop While c_flux.DataAvailable
' Print out the received message to the console.
Return c_message.ToString()
Else
Return "Sorry. You cannot read from this NetworkStream."
End If
End Function
Sub EcrireFlux(ByVal p_message As String)
c_buffer = System.Text.Encoding.ASCII.GetBytes(p_message)
c_flux.Write(c_buffer, 0, c_buffer.Length)
End Sub
End Class |
Partager