I have a client/server program that runs great on many private machines. However, once I install the server on a host domain of Amazon Lightsail, Windows Server 2016, I get an exception.
I am using UDP socket and trying to bind with the static IP I have but I am getting this exception:
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)
I have tried many different ports as well as zero.
My code:
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);
I doubt the problem is in the code because as I said the server has been tested and runs great on more than one machine.
I'm guessing its something with Windows or server setting, I turned firewall off and tried inbound all UDP reference.