1
I’m having a hard time using a reverse connection between client and server. Whenever I try to connect using Dns or Ip does not connect, if I use Localhost, 127.0.0.1, it connects perfectly. It can already "solve" the DNS IP What I need to do to connect ?
private static Socket _clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public static TcpClient client;
private const int _PORT = 28562; // porta
public static string connectTo = "decodertm.ddns.net";// Não conecta
// public static string connectTo = "127.0.0.1";// conecta
public static IPAddress ipaddress = null;
.
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("Tentativas de conectar " + attempts);
_clientSocket.Connect("177.201.126.8", _PORT);
Thread.Sleep(100);
}
catch (SocketException)
{
Console.Clear();
}
}
Console.Clear();
Console.WriteLine("Conectado !");
}