Tcp client in xamarin does not connect

300 views Asked by At

I have a problem of client doesn't connect to the server. They are on the same port. I have the right IP address. I wrote a similar program in C# and it connects.

How can I solve it?

I have an Entry called "IpAd", where I write the IP address

private void Connect_Clicked(object sender, EventArgs e)
{
    string[] ip = new string[3];
    ip = IpAd.Text.Split('.');
    for (int i = 0; i<=3;i++)
    {
        if (int.Parse(ip[i]) > 255 || int.Parse(ip[i]) < 0 || IpAd.Text == "")
        {
            Connected.Text = "Incorrect Ip";
            Connected.TextColor = Color.Red;
            return;
        }
    }
    try
    {
        _sender = new TcpClient(IpAd.Text.ToString(), 11000);

        Connected.Text = "Client Online";
        Connected.TextColor = Color.Green;
        
        stream = _sender.GetStream();

        Connected.Text = "Connected";
        Connected.TextColor = Color.Green;
        Can_send = true;
    }
    catch (SocketException ee)
    {
        Console.WriteLine("SocketException: {0}", ee);
        Connected.Text = "Socket Not Connected";
        Connected.TextColor = Color.Red;
    }
    catch
    {
        Connected.Text = "Not Connected";
        Connected.TextColor = Color.Red;
    }
}
0

There are 0 answers