C# SOCKET 问题
高手请看下面的代码为什么不能执行啊?会报出参数有误的错误
这可是从MSDN里copy出来的
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
IPHostEntry lipa = Dns.Resolve("localhost");
IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 5151);
Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);
try
{
// Creates an IpEndPoint to capture the identity of the sending host.
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tempRemoteEP = (EndPoint)sender;
// Creates a byte buffer to receive the message.
byte[] buffer = new byte[1024];
// Receives datagram from a remote host. This call blocks.
s.ReceiveFrom(buffer,0,100,SocketFlags.None, ref tempRemoteEP);
// Displays the information received to the screen.
Console.WriteLine(" I received the following message : " +
Encoding.ASCII.GetString(buffer) );
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.ToString() );
}
}