Hello, i want to download the webpage of a website using UDP protocol. I only know how to do this using TCP protocol using TCPClient. But this time around, i need to do the same task using UDP protocol and i am clueless. Pls any help will be appreciated.
Here is the sample code of what i am trying to implement. But this example uses TCP protocol. But i need to do the same thing using UDP protocol.
Dim c As New TcpClient
Dim i As Integer
Dim nw As NetworkStream
c.Connect("www.google.com", 80)
nw = c.GetStream()
Dim packet As String = "GET http://www.google.com/ HTTP/1.1" & vbCrLf & _
"Host: www.google.com" & vbCrLf & _
"Connection: Close" & vbCrLf & vbCrLf
Dim toSend As Byte() = Encoding.ASCII.GetBytes(packet)
nw.Write(toSend, 0, toSend.Length)
Dim buffer(1024) As Byte
Dim received As String = ""
While True
i = nw.Read(buffer, 0, buffer.Length)
If i = 0 Then
c.Close()
Exit While
End If
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, i))
End While
Console.WriteLine("Finished Receiving....")
Console.ReadLine()
If you can help me re-write the sample code to use UDP protocol instead of the TCP, it will be greatly appreciated. And if also i need to use raw sockets and set the protocol to UDP. Pls any help will be greatly appreciated.
Thanks