title: Not able to connect Node.js server using Socket.Io.Client from Xamarin.Android client
body: <p>I am trying to implement Socket.Io client in my chat application using Xamarin Android.
  For validation I am using my physical device. In debug, noticed Socket gets connect only once I launch and for rest of the times it gives java.Lang.Object error when reopen the app background. Also this works one time when I uninstall and reinstall again in the device. Please suggest to fix this.</p>
  <p>Below steps have been followed to setup :</p>
  <ol>
  <li>Set the IOOptions inside onCerate method.</li>
  <li>OnResume checking the socket and closing and opening</li>
  <li>Used android:usesCleartextTraffic=&quot;true&quot;  in Manifest file</li>
  <li>Validating with API level 29</li>
  </ol>
  <p>Your help would be greatly appreciated</p>
  <p><strong>Server Side(Node.js) Implementation:</strong></p>
  <pre><code>var port =0000;
  var app = require('express')();
  var bodyParser = require('body-parser');
  var jwt = require('jsonwebtoken');
  var favicon = require('serve-favicon');
  var concurents = {};
  
  var fs = require('fs');
  
  var pkey = fs.readFileSync('ssl/xyz.pem');
  var pcert = fs.readFileSync('ssl/abc.pem');
  
  var options = {key: pkey,cert: pcert};
  var http = require('https').Server(options, app);
  var io = require('socket.io')(http,{transports: ['websocket'],  upgradeTimeout: 10000,  
  allowUpgrades: false,  pingTimeout: 10000,  pingInterval:5000,  });
          
  </code></pre>
  <p><strong>Client Side(Android) Implementation:</strong></p>
  <p>OnCreate:</p>
  <pre><code>IOOption = new IO.Options()
          {
              Query = &quot;key=xxxxx&amp;domain=xxxxx&amp;origin=xxxxx&quot;,
              Reconnection = true,
              Timeout = 60000,
              ReconnectionDelay = 1000,
              ReconnectionAttempts = 999999999,
              ForceNew = true,
              Secure = true,
              Upgrade = false,
              Host = &quot;111.xxx.xxx.xxx&quot;,
              Hostname = &quot;xxxxx&quot;,
              Port = xxxx,
              Transports = new string[1] { WebSocket.TransportName }
          };
  </code></pre>
  <p>onResume:</p>
  <pre><code>    if (socket != null)
          socket.Close();
      
      socket = IO.Socket(&quot;https://domain:port&quot;, IOOption);
  
      socket.On(Socket.EventConnect, (data) =&gt;
              {
                  socket.Emit(&quot;connect_user&quot;, 123);
                  AttachSocketEvents(socket);
              });
              socket.On(Socket.EventConnectError, (data)=&gt; {
                  Console.WriteLine(&quot;Connection failed&quot;);
              });
              socket.On(Socket.EventConnecting, (data) =&gt; {
                  Console.WriteLine(&quot;Connecting failed&quot;);
              });
              socket.On(Socket.EventError, (data) =&gt; {
                  Console.WriteLine(&quot;EventError failed&quot;);
              });
             socket.Connect();
             
  </code></pre>