我正在使用UDP套接字并尝试与我拥有的静态IP绑定,但是却遇到此异常:
System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at AP_Server_Side.Program.Main(String[] args)
我尝试了许多不同的端口以及零端口。
我的代码:
Socket _reciveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress _localAddress = IPAddress.Parse("52.56.192.252");
IPEndPoint _localip = new IPEndPoint(_localAddress, 0);
Console.WriteLine("local Address : " + _localip.ToString());
IPEndPoint _newend = new IPEndPoint(IPAddress.Any, 0);
EndPoint _escoler = (EndPoint)_newend;
byte[] _bufferrecived = new byte[1024];
byte[] _sendBuffer = new byte[1024];
int _recivefrom;
string _msgRecived = string.Empty;
int _userint = 1;
try
{
_reciveSocket.Bind(_localip);
我怀疑问题出在代码中,因为正如我所说的那样,服务器已经过测试,并且可以在多台机器上良好运行。
我猜测它与Windows或服务器设置有关,我关闭了防火墙并尝试入站所有UDP参考。
我有一个客户端/服务器程序,可以在许多私人计算机上很好地运行。但是,一旦将服务器安装在Amazon Lightsail的主机域Windows Server 2016上,就会出现异常。我正在使用...