how to connect localhost from IOS simulator?

batmacibatmaci DEMember ✭✭✭✭✭

I am trying to connect my Windows PC's localhost over IOS simulator which is remotely connected to Mac but code below although works fine on Android, it doesnt work for IOS, it keeps returning Connection refused. It was said that IOS simulator is running on host machine and it should work using localhost directly. If i try to use IP address of remote MAC, it doesnt refuse the connection but it returns "connection time out" exception. I tested and simulator has internet connection. How can I achieve to connect to localhost from simulator?

  var c = new TcpClient();
                try
                {
                    if (Device.RuntimePlatform == Device.Android)
                        c.Connect(IPAddress.Parse("10.0.2.2"), 6000);
                    else
                        c.Connect(IPAddress.Parse("127.0.0.1"), 6000);
                }
                catch (Exception ex)
                {

                }

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭

    @batmaci said:

    I am a little confused by your wording, but from your code sample I see you are attempting to connect to 127.0.0.1 in your app, where you are expecting 127.0.0.1 to be your Windows PC, is that right?
    That probably wont work, you would need to connect to the Windows PC ip address (or its network name).

  • batmacibatmaci DEMember ✭✭✭✭✭

    @JohnHair yes i tried that also but it returns always connection timed out. i dont know why. i turned off firewall also and simulator has internet connection.

  • JohnHJohnH GBMember ✭✭✭✭✭
    edited January 5

    @batmaci said:
    @JohnHair yes i tried that also but it returns always connection timed out. i dont know why. i turned off firewall also and simulator has internet connection.

    Hmm, can you use Safari on the iOS simulator to show a hello world html page that you host on your Windows PC? If connected to the same network that will work with IP address and / or machine name.

Sign In or Register to comment.