一个简单的问题--Socket.ReceiveFrom函数的用法
using System;
using System.Net;
using System.Net.Sockets;
namespace server
{
class Class1
{
static void Main(string[] args)
{
Socket myso=new Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.Icmp);
byte[] rcvBuf=new byte[256];
IPEndPoint remoteIP=new IPEndPoint(IPAddress.Parse("172.16.11.22"),0);
EndPoint remoteEP=(remoteIP);
while(true)
{
int nBytes=myso.ReceiveFrom(rcvBuf,256,0,ref remoteEP);
Console.WriteLine(remoteEP.ToString());
}
}
}
}
我想写一个接收ICMP数据包的程序,可是上述程序总是说执行ReceiveFrom函数那句出错:"An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll
Additional information: 提供了一个无效的参数。"
请教一下各位大侠应该怎么改,这个程序是想接受所有的ICMP包的,ReceiveFrom函数中的最后一个EndPoint参数我记得好象是用来存储远程主机的信息的,所以原来为空应该也可以,可是若这个参数开始没有赋值,就提示使用了未赋值的参数,给他赋值,又提示上述错误,哪位大侠帮帮我吧!!