Bonjour,
je suis coincé sur un problème depuis quelques jours...
le problème est le suivant,
j'utilise un TCPClient pour me connecter à un port particulier
jusque là, la connexion se fait bien, je reçois une belle réponse du serveur
directement (networkstream et tcpclient sont toujours ouverts!) j'écris un autre message (commande), le serveur me réponds toujours.
et à la 3e écriture, il me plante... la propriété "DataAvailable" du networkstream est à false... impossible d'avoir une réponse du serveur !
je ne comprends pas...
quelqu'un peut m'aider?
Merci d'avance
Public Function Connect() As Boolean Dim bytes As Int32 Dim responseData As String Try Me._client = New TcpClient(Me._server, Me._port) ' Get a client stream for reading and writing. Me._client.NoDelay = True Me._stream = Me._client.GetStream() Me._buffer = New Byte(Me._client.ReceiveBufferSize) {} bytes = Me._stream.Read(Me._buffer, 0, Me._buffer.Length) responseData = System.Text.Encoding.ASCII.GetString(Me._buffer, 0, bytes) If responseData.Trim.ToLower.Contains("playbox") Then Return True Else Return False End If Catch ex As Exception Return False End Try Return True End Function Public Sub Disconnect() If Me._client IsNot Nothing Then Me._client.Close() End If If Me._stream IsNot Nothing Then Me._stream.Close() End If End Sub Private Function SendCommand(ByVal Message As String) As String 'Dim data As Byte() 'data = System.Text.Encoding.ASCII.GetBytes(Message) 'Me._stream.BeginWrite(data, 0, data.Length, AddressOf DataSent, Nothing) ' String to store the response ASCII representation. Dim responseData As String Dim bytes As Int32 If Me._client.Connected AndAlso Me._stream.CanRead AndAlso Me._stream.CanWrite Then Try ' Translate the passed message into ASCII and store it as a Byte array. Me._buffer = System.Text.Encoding.ASCII.GetBytes(Message) Me._stream = Me._client.GetStream With Me._stream If .CanWrite AndAlso .CanRead Then ' Send the message to the connected TcpServer. .Write(Me._buffer, 0, Me._buffer.Length) '.BeginWrite(Me._buffer, 0, Me._buffer.Length, AddressOf DataSent, Nothing) '.ReadTimeout = 30000 ReDim Me._buffer(Me._client.ReceiveBufferSize) bytes = .Read(Me._buffer, 0, Me._buffer.Length) ' Read the first batch of the TcpServer response bytes. responseData = System.Text.Encoding.ASCII.GetString(Me._buffer, 0, bytes) Return responseData Else Return String.Empty End If End With Catch ex As Exception Return String.Empty End Try Else Return String.Empty End If End Function