Click here to Skip to main content
15,885,546 members

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.

VB
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: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900