title: Xamarin - Socket IO issue
body: <p>I have to make a chat for a Xamarin Forms (PCL) application. I'm using the NuGet package SocketIoClientDotNet for socket.</p>
  
  <p>At first I could not connect at all. After many researches on internet I found <a href="https://github.com/Quobject/SocketIoClientDotNet/issues/127" rel="nofollow noreferrer">this open issue</a> on Github, so I downgraded the library but also all the dependencies:</p>
  
  <ul>
  <li>EngineIOClient.Net V0.9.22</li>
  <li>SocketIOClientDotNet V0.9.13</li>
  <li>WebSocket4Net V0.14.1.0</li>
  </ul>
  
  <p>It was better, the connection seemed to work but I encountered a new issue: the connection is very instable and it's difficult for me to test anything cause of that. One time it can connect multiple times, one time it not connect at all, it's very annoying... </p>
  
  <p>My code is very simple:</p>
  
  <p><strong>Common Code:</strong></p>
  
  <p><em>ISocketIO interface:</em></p>
  
  <pre><code>public interface ISocketIO
  {
      void Connect(string url);
      void On(string eventString, Action&lt;object&gt; action);
  }
  </code></pre>
  
  <p><em>MsgService class:</em></p>
  
  <pre><code>readonly string EVENT_CONNECT = "connect";
  public MsgService(ISocketIO socket)
  {
      Socket = socket;
  
      if (Socket != null)
      {
          Socket.On(EVENT_CONNECT, () =&gt;
          {
              (code here...)
          });
      }
  }
  
  public void Connect()
  {
      if (Socket != null)
      {
          Socket.Connect("chat_url_here");
      }
  }
  </code></pre>
  
  <p><em>App class:</em></p>
  
  <pre><code>public partial class App : Application
  {
      public static MsgService MsgService;
  
      public App(ISocketIO socket)
      {
          InitializeComponent();
  
          Language = Language.FRENCH;
          MsgService = new MsgService(socket);
          MsgService.Connect();
          MainPage = new NavigationPage(new MainPage());
      }
  
      ...
  }
  </code></pre>
  
  <p><strong>iOS code (same for Android):</strong></p>
  
  <p><em>Class SocketIO</em></p>
  
  <pre><code>[assembly: Xamarin.Forms.Dependency(typeof(SocketIO))]
  namespace MeetYou.iOS
  {
      public class SocketIO : ISocketIO
      {
          Socket _socket;
  
          public void Connect(string url)
          {
              IO.Options opt = new IO.Options
              {
                  Path = "path_here"
              };
              _socket = IO.Socket(url, opt);
              _socket.Connect();
          }
      }
  }
  </code></pre>
  
  <p><em>AppDelegate:</em></p>
  
  <pre><code>[Register("AppDelegate")]
  public class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
  {
      public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
      {
          Xamarin.Forms.Forms.Init();
          LoadApplication(new App(new SocketIO()));
  
          return base.FinishedLaunching(uiApplication, launchOptions);
      }
  }
  </code></pre>
  
  <p>Maybe I'm doing something wrong of maybe it exists an other plugin I could use instead this one.</p>