Click here to Skip to main content
13,193,551 members (38,005 online)

downloading the source of a webpage using UDP protocol

Joeadeoye asked:

Open original thread
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)
 
        'reading response
        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
Tags: VB, VB.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy |
Web01 | 2.8.171018.2 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
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