Previously I had problem to connecting my client and server using DNS Server, because I could not solve the ip,
public static TcpClient client;
private const int _PORT = 100; // same as server port
public static string connectTo = "kamikazehc.ddns.net";
public static IPAddress ipaddress = null;
resolving IP addresses into DNS name:
private static void ConnectToServer()
{
int attempts = 0;
bool IsValidIP = IPAddress.TryParse(connectTo, out ipaddress);
if (IsValidIP == false)
{
ipaddress = Dns.GetHostAddresses(connectTo)[0];
Console.WriteLine(Dns.GetHostAddresses(connectTo)[0]);
}
client = new TcpClient();
while (!_clientSocket.Connected)
{
try
{
attempts++;
Console.WriteLine("Connection attempt " + attempts);
_clientSocket.Connect(ipaddress, _PORT);
Thread.Sleep(100);
}
catch (SocketException)
{
Console.Clear();
}
}
Console.Clear();
Console.WriteLine("Connected");
}
If I put my local Ip 192.168.x.x I connect. But if I use my fixed IP or dns the client makes endless attempts to connect.
Using DNS or Fixed IP
Using local IP:
I would like to know how to solve this to be able to connect, I imagine I do not need to modify the code, just configure my internet, but I do not know how to configure