public void OpenConnection(String URL) { //DependencyService.Get<backservices>().returnprincipal("regresando", "regresando"); //App mp = (App)Xamarin.Forms.Application.Current; //MessagingCenter.Send<object, string>("texto", "Hi", "StackOverFlow Rocks"); //MessagingCenter.Send("texto", "Hi", "Connected to Socket.io "); //Notificacion.Notificacion n = new Notificacion.Notificacion("Test notification offline"); var option = new IO.Options { Reconnection = true, ReconnectionDelay = 1000, ReconnectionDelayMax = 3000, Timeout = 20000, ForceNew = true }; var socket = IO.Socket(URL, option); socket.On(Socket.EVENT_CONNECT, () => { //socket.Emit("hi"); //MessagingCenter.Send("texto", "Hi", "Connected to Socket.io "+ URL); socket.Emit("MovilToSocket", "mensaje a socket"); }); socket.On("hi", (data) => { Console.WriteLine(data); socket.Disconnect(); }); socket.On("MensajeSocket", (data) => { RespuestaSocketIO resp = JsonConvert.DeserializeObject <RespuestaSocketIO>((string)data); //MessagingCenter.Send("texto", "Hi", "Mensaje " + resp.Mensaje); Notificacion.Notificacion n = new Notificacion.Notificacion("Mensaje " + resp.Mensaje); }); //socket.Connect(); //Console.ReadLine(); }
public void OpenConnection(string URL) { var socket = IO.Socket(URL); socket.On(Socket.EVENT_CONNECT, () => { //socket.Emit("hi"); //MessagingCenter.Send("texto", "Hi", "Connected to Socket.io "+ URL); socket.Emit("MovilToSocket", "mensaje a socket"); }); socket.On("hi", (data) => { Console.WriteLine(data); socket.Disconnect(); }); socket.On("MensajeSocket", (data) => { RespuestaSocketIO resp = JsonConvert.DeserializeObject <RespuestaSocketIO>((string)data); MessagingCenter.Send("texto", "Hi", "Mensaje " + resp.Mensaje); }); }