C#C
C#3y ago
iskander

✅ TcpClient is connected to TcpListener but TcpListener isn't connected...

so this is how i accept clients which passes through with no issues. i've made to sure to catch any errors that could result from function and none is thrown...
public static async Task<bool> AcceptClient(CancellationToken Token)
    {
        if (!IsServer())
        {
            return false;
        }
        Server.Start();
        TcpClient JoinedClient = await Server.AcceptTcpClientAsync(Token);
        Server.Stop(); 

        if (JoinedClient != null)
        {
            Clients.Add(JoinedClient);
            return true;
        }
        else
        {
            return false;
        }
    }

this is how the client attempts to connect to the server. this result in a successful connection.
public static async Task<bool> JoinServer(string IpAddress)
    {
        Client = new TcpClient();
        
        if (IPEndPoint.TryParse(IpAddress, out IPEndPoint Result))
        {
            Result.Port = Port;
            await Client.ConnectAsync(Result);
            return true;
        }
        else
        {
            Client = null;
            return false;
        }
    }

my pc is the server while my phone is the client. they're in the same network but i havent touched the firewall settings in my pc yet but i assume that wont cause this issue...
Was this page helpful?