Click here to Skip to main content
11,926,429 members (59,758 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET Sockets
Hello friends, how can i download a webpage using socket. I know how to do this using TcpClient() but i want to do it using socket. I want to do something like this:
Dim cs As New TcpClient
cs.Connect("", 80)
Dim nw as NetworkStream = cs.GetStream()
Dim buffer(1024) As Byte
Dim hdr_request As String = "GET / HTTP/1.1" & VbNewLine
hdr_request = hdr_request & "Host:"  & VbNewLine
hdr_request = hdr_request & "Connection: Close"  & VbNewLine & VbNewLine
Dim toSend As Byte() = Encoding.ASCII.GetBytes(hdr_request)
nw.Write(toSend, 0, toSend.Length)
'reading response
Dim c As Integer
While True
   c = nw.Read(buffer, 0, buffer.Length)
   If c = 0 Then
      Exit While
   End If
   Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, c))
End While

I want to do something like this using socket. The above example is done using TcpClient but i want to re-do it using socket, send(), recv() e.t.c.
Please help me re-write the above example using socket instead of TcpClient i used!
Please Help Me!!!!!

My second question is that can a TcpClient connect to SSL socket?
I try to connect something like tcpClient.Connect("" 443) i got an error "No Such Host is Known" i even try tcpClient.Connect("ssl://", 443) i got the same error. But if i do it in PHP using the fsockopen() function to connect i.e. fsockopen("ssl://", 443) it works well. So what is wrong with
Posted 6-Jun-12 20:38pm
Edited 6-Jun-12 20:50pm
SAKryukov 17-Jun-12 21:56pm
Why would anyone help you if you even don't explain why do you want to re-write the code this way?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 17 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100