我正在编写此代码以获取来自客户端的数据包:
byte[] input = BitConverter.GetBytes(1);
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Parse("46.105.248.69"), 1369));
s.IOControl(IOControlCode.ReceiveAll, input, null);
int bytes;
bytes = s.Receive(buffer);
while (bytes > 0)
{
label1.Text = System.Text.Encoding.ASCII.GetString(buffer, 0, bytes);
bytes = s.Receive(buffer);
}
但是当我运行此代码时,我收到此错误:
未处理的类型' System.Net.Sockets.SocketException'发生在System.dll中 附加信息:尝试以其访问权限禁止的方式访问套接字
此行错误:
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
我该如何解决这个问题?