0
下面的代碼在語句中總是拋出一個異常: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());
}
}
}
}