Answer the question
In order to leave comments, you need to log in
Why does it work fine on an android emulator but not on a real phone?
In Visual Studio 2017 in C# I make an application with Socket.IO.Client and run it in the emulator (Android 6.0 and 8.0) - everything works like clockwork.
I archive and install on the phone (Android 6.0) - Socket.IO.Client does not work.
Could you help me, tell me why?
MainActivity.cs
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using SocketIO.Client;
using System.Threading;
namespace App6
{
[Activity(Label = "Программулина", Theme = "@style/AppTheme", MainLauncher = true, Icon ="@mipmap/exit")]
public class MainActivity : AppCompatActivity
{
private Socket socket;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
TextView info = FindViewById<TextView>(Resource.Id.textView1);
info.Text = "Проверочка";
//ДО СЮДА ВЫПОЛНЯЕТСЯ
socket = IO.Socket("http://192.168.0.100:3333");
socket.Connect();
socket.On(Socket.EventConnect, (data) => {
Print("Коннект", info);
socket.Emit("add user", "Xamarin Android");
});
socket.On("message",(data)=>
{
Print(data[0].ToString(), info);
});
}
private void Print (string text, TextView info)
{
RunOnUiThread(() => { info.Text = text; });
}
}
}
<uses-permission android:name="android.permission.INTERNET" />
Answer the question
In order to leave comments, you need to log in
Debugger / logs in the teeth and watch.
There are a lot of options - from the lack of IP to the lack of permissions to access the application in the network.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question