Click here to Skip to main content
12,554,442 members (66,084 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("", 80)
nw = c.GetStream()
Dim packet As String = "GET HTTP/1.1" & vbCrLf & _
"Host:" & 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
        Exit While
    End If
    Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, i))
End While
Console.WriteLine("Finished Receiving....")

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.

Tags: VB, VB.NET


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 | Mobile
Web02 | 2.8.161021.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2016
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