title: How to make sockets work in xamarin?
body: <p>In the Answer to this question Here:<a href="https://stackoverflow.com/questions/36823404/server-client-application-with-net-and-xamarin">Server Client Application with .NET and Xamarin</a>
  the person who answered said: "On Xamarin.Android you can use all of the regular .Net socket classes"
  I tried using the code in example of the Microsoft documentation and i had no errors but application just is just displaying like that on the phone:
  <a href="https://i.stack.imgur.com/lNnVE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lNnVE.png" alt="enter image description here"></a></p>
  
  <p>If I delete the socket code it would display the page normally.My code behind:</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using Xamarin.Forms;
      using Xamarin.Forms.Xaml;
      using System.Net;
      using System.Net.Sockets;
  
      namespace App14
       {
       [XamlCompilation(XamlCompilationOptions.Compile)]
       public partial class Page2 : ContentPage
       {
      public static string data = null;
  
      public static void StartListening()
      {
          // Data buffer for incoming data.  
          byte[] bytes = new Byte[1024];
  
  
          // Establish the local endpoint for the socket.  
          // Dns.GetHostName returns the name of the   
          // host running the application.  
          IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
          IPAddress ipAddress = ipHostInfo.AddressList[0];
          IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
  
          // Create a TCP/IP socket.  
          Socket listener = new Socket(ipAddress.AddressFamily,
              SocketType.Stream, ProtocolType.Tcp);
  
          try
          {
              listener.Bind(localEndPoint);
              listener.Listen(10);
  
  
              // Start listening for connections.  
              while (true)
              {
                  var label = new Label() { Text = "searching for a connection" };
                  // Program is suspended while waiting for an incoming connection.  
                  Socket handler = listener.Accept();
                  label.Text = "Found a Connection";
                  data = null;
  
                  // An incoming connection needs to be processed.  
                  while (true)
                  {
                      int bytesRec = handler.Receive(bytes);
                      data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                      if (data.IndexOf("&lt;EOF&gt;") &gt; -1)
                      {
                          break;
                      }
                  }
  
                  // Show the data on the console.  
                  label.Text = "Text received" + data;
  
                  // Echo the data back to the client.  
                  byte[] msg = Encoding.ASCII.GetBytes(data);
  
                  handler.Send(msg);
                  handler.Shutdown(SocketShutdown.Both);
                  handler.Close();
              }
  
          }
          catch (Exception e)
          {
              Console.WriteLine(e.ToString());
          }
  
  
      }
  
      public Page2 ()
      {
          StartListening();
          Title = "Sign in page";
          InitializeComponent();
  
      }
     private void page2_click(object sender,EventArgs e)
      {
          Navigation.PushAsync(new Page1(), true);
      }
  }
  }
  </code></pre>
  
  <p>Xaml File code:
  <a href="https://i.stack.imgur.com/6CZYh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CZYh.png" alt="enter image description here"></a></p>
  
  <p>Why is this?.and can you please provide an example of client mobile or server mobile socket</p>