我正在尝试建立反向连接,但没有任何反应 系统只会尝试无限连接
客户代码:
private static Socket _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public static TcpClient client;
private const int _PORT = 28562; //port
public static string connectTo = "example.ddns.net"; //addres
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("Connection attempt " + attempts);
_clientSocket.Connect(ipaddress, _PORT);
Thread.Sleep(100);
}
catch (SocketException)
{
Console.Clear();
}
}
Console.Clear();
Console.WriteLine("Connected");
}
我可以进行哪些更改以能够连接?