A
A
Auratos2019-08-18 10:10:41
client-server
Auratos, 2019-08-18 10:10:41

Xamarin Forms. Android. How to properly organize access to the socket server?

Good afternoon. I am developing in Xamarin Forms for Android. I'm trying to raise a socket server on a smartphone. The client is a console application.
I get the address of the server (smartphone) as follows:

IPAddress[] adresses = Dns.GetHostAddresses(Dns.GetHostName());
if (adresses != null && adresses[0] != null)
{
      adr = adresses[0].ToString();
}
strendpoint = adr + ":2780";
IPEndPoint localEndPoint = CreateIPEndPoint(strendpoint);
_server = new TcpListenerServer(localEndPoint);

Then I go to 2ip.ru from my smartphone, find out my IP and drive it into the client:
const int port = 2780;
const string address = "85.26.233.137";
client = new TcpClient(address, port);
NetworkStream stream = client.GetStream();

So. The client thus cannot reach the server. If I connect my smartphone to my home Wi-Fi (that is, both the server and the client are now on the same network), and its address becomes something like 192.168.0.105, then the client can connect to this address.
I noticed that the address that 2ip.ru gives out when I work through an operator (Megafon) differs from the address that is indicated in the phone parameters in the "About the device" section - there it is 100.99.225.236. But the client cannot reach this address either. Can you please tell me how to organize this system?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question