我试图与发送UDP HTTP GET请求(因为从监听服务器的回复是不相关的,我不想阻止此程序)UDP数据永不发送?
这是代码:
System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();
client.Connect("www.domainname.com", 80);
string request_header = "GET /ping.php HTTP/1.1\r\nHost: www.domainname.com\r\n\r\n";
byte[] stre = System.Text.Encoding.ASCII.GetBytes(request_header);
client.Send(stre, stre.Length);
System.Net.IPEndPoint RemoteIpEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
byte[] receiveBytes = client.Receive(ref RemoteIpEndPoint);
string returnData = System.Text.Encoding.ASCII.GetString(receiveBytes);
client.Close();
首先,请求似乎没有在服务器上被接收到,所以我想在发送时可能会出现错误? 其次,程序挂在client.Receive(参考RemoteIpEndPoint)上,并在那里等待。似乎没有收到任何数据。
我曾试图改变......
System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
到...
System.Net.IPEndPoint(System.Net.IPAddress.Any, 80);
...但没有运气。
HTTP over UDP,认真吗?服务器是否在端口80上侦听UDP请求?我对此表示怀疑。只需使用TCP并完成它。 – 2011-02-25 15:21:57
好吧,所以UDP可能是错误的方式呢?我真正想要的是以最少的流程消耗方式来发送GET请求(不阻塞发送客户端) – hbruce 2011-02-25 16:09:53