1

I want to make connection between android to windows. I am using xamarin and visual studio. My android client code work on android emulator but when I was a try on my android phone, program gives "could not resolve host localhost". My problems are shown below.

try
{  
    //binaryserver.....  
    BinaryServerFormatterSinkProvider sProvider = new BinaryServerFormatterSinkProvider();

    //Binary type
    sProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
    //Binary provider for client
    BinaryClientFormatterSinkProvider cProvider = new BinaryClientFormatterSinkProvider();

    //give key and port to Hashtable for add channel

    Hashtable ha = new Hashtable();

    ha.Add("port", "0"); 

    //create a channel
    TcpChannel kanal = new TcpChannel(ha, cProvider, sProvider);
    //ChannelServices.UnregisterChannel(kanal);
    ChannelServices.RegisterChannel(kanal);
    //register channel

    //get url
    string url = "tcp://192.168.1.38:1453/MSN";

    //ve hangi tipde değerlerin gönderileceği ile ilgili bilgi verdim url denilen değişken ile de bağlantı  cümlesi oluşturdum...
    RemotingConfiguration.RegisterWellKnownClientType(typeof(MYCLASS), url);

    nesne = new MsnNesne();
    olay = new MsnOlay();

    olay.MesajGeldi += olay_MesajGeldi;
    nesne.MesajGeldi += olay.MesajGeldi_olayin_TetiklendiğiVoid;
}
catch (Exception ex)
{
    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
}

Thanks for your help.

Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
  • 1
    Your code shows that you're using an IP address, but you say the error message says "localhost". Which is correct? Is your phone on the same subnet as the test server? Does your app have INTERNET_PERMISSIONS enabled in the manifest? Have you tested connectivity to the server using the phone's browser? – Jason Mar 15 '16 at 22:24
  • you can see http://stackoverflow.com/questions/4905315/error-connection-refused – MohammadReza Moradi Oct 06 '16 at 16:41
  • If you're still facing the issue, feel free to give this a try : https://stackoverflow.com/a/67032554/12298875 – Omar Khaium Chowdhury Apr 10 '21 at 09:06

0 Answers0