C# SOCKET 问题

large_small large_small 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
高手请看下面的代码为什么不能执行啊?会报出参数有误的错误
这可是从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() );
}
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
large_small
C# 111,128 成员 642,536 内容