使用UDP协议下载网页的源 [英] downloading the source of a webpage using UDP protocol

查看:95
本文介绍了使用UDP协议下载网页的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用UDP协议下载网站的网页。我只知道如何使用TCPClient使用TCP协议。但这一次,我需要使用UDP协议执行相同的任务,我无能为力。请帮助任何帮助。



这是我想要实现的示例代码。但是这个例子使用TCP协议。但我需要使用UDP协议做同样的事情。



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()





如果您可以帮我重新编写示例代码以使用UDP协议而不是TCP,我们将不胜感激。如果我还需要使用原始套接字并将协议设置为UDP。非常感谢任何帮助。



谢谢



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

推荐答案

HTTP分层在TCP之上协议 - 所以除非你也写服务器,否则你将无法使用UDP。



祝你好运

Espen Harlinn
HTTP is layered on top of the TCP protocol - so you will not be able to use UDP unless you also write a server.

Best regards
Espen Harlinn


@Espen Harlinn感谢您的回复。对此,我真的非常感激。所以,你在本质上说的是我还需要编写一个服务器来接收从客户端发送的HTTP头请求,然后再处理它。如果我做对了,我可以用什么语言编写服务器应用程序?我可以使用PHP或ASP.NET
@Espen Harlinn thank you for your reply. I really appreciate it. So, what you are saying in essence is that i also need to write a server that will "receive" the HTTP header request sent from the client and later process it. If i got it right, what language can i use to write the server application? can i use PHP or ASP.NET


如果你在谈论一个你不能控制的网站,你不能使用UDP,因为HTTP建立在TCP之上,而不是UDP 。



如果您正在控制客户端应该从中获取网页的Web服务器和服务器端代码,那么您可以编写Web服务器使用你想要的任何语言。虽然,我几乎没有看到在UDP之上编写HTTP服务器的重点,因为传输HTML时的任何错误都会使页面无效。
If you''re talking about a web site that you do NOT control, you cannot use UDP as HTTP is built on top of TCP, not UDP.

If you''re controlling the web server and server-side code that the client is supposed to be getting web pages from, then you can write the web server using any language you want. Though, I hardly see the point of writing a HTTP server on top of UDP since any mistake in transmitting the HTML will render the page useless.


这篇关于使用UDP协议下载网页的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆