套接字 - 数据包发送异常

时间:2013-12-14 19:01:35

标签: c# .net sockets ip packets

我写了以下代码:

byte[] packetdata = System.Text.ASCIIEncoding.ASCII.GetBytes("<hello world>");
            string ip = "000.000.000.000";
            int port = 80;
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port);
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            client.SendTimeout = 1;
            while (true) client.SendTo(packetdata, ep);

我尝试输入多台计算机的IP地址(测试目的),每次都会在几秒钟后抛出异常。

例外:

SocketException was unhandled: A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond

这是什么意思?计算机的IP受到网络压力攻击的保护吗? 或者只是代码错误?

0 个答案:

没有答案