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
| Try
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("90.54.194.209", 2503) 'l'adresse ip de la cible
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As Byte() = Encoding.ASCII.GetBytes("Le texte a envoyer.")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
MsgBox("Host returned: " & returndata & vbCrLf)
Else
If Not networkStream.CanRead Then
MsgBox("cannot not write data to this stream" & vbCrLf)
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
MsgBox("cannot read data from this stream" & vbCrLf)
tcpClient.Close()
End If
End If
End If
Catch ex As Exception
MsgBox(ex.Message & vbCrLf)
End Try |
Partager