UDPClient构造函数一直抛出错误:10022
问题描述:
下面的代码在语句中总是抛出一个异常:UdpClient receivingUdpClient = new UdpClient(); 它引发的错误代码是10022,它是无效参数。我不确定构造函数如何抛出这个错误。UDPClient构造函数一直抛出错误:10022
在此先感谢您提供的任何帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace Test_UDP_Console_program
{
class Program
{
private const int listenPort = 4999;
static void Main(string[] args)
{
try
{
UdpClient receivingUdpClient = new UdpClient();
receivingUdpClient.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.255"), 4999));
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
string returnData = System.Text.Encoding.ASCII.GetString(receiveBytes);
receivingUdpClient.Close();
}
catch(SocketException e)
{
Console.WriteLine(e.ErrorCode.ToString());
}
}
}
}
答
事实证明,当使用套接字时,您必须从本地驱动器运行程序,而不是由于某种原因运行网络驱动器。