Well, it depends on what you want to get back. Here's a quick example that access www.microsoft.com:
However if you want to access web servers you should really look into the WebClient class instead of using TcpClient.Code:Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim client As New TcpClient() client.Connect("www.microsoft.com", 80) Dim textToSend As String = "GET / HTTP/1.1" & vbCrLf & _ "Host: microsoft.com" & vbCrLf & _ vbCrLf Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(textToSend) Using stream As NetworkStream = client.GetStream() stream.Write(data, 0, data.Length) data = New Byte(1024) {} Dim bytes As Integer = 0 Dim responseText As String = "" Do bytes = stream.Read(data, 0, data.Length) responseText &= System.Text.Encoding.ASCII.GetString(data, 0, bytes) Loop While stream.DataAvailable MessageBox.Show(responseText) End Using client.Close() End Sub




Reply With Quote