title: How can I use Socket in Blazor Client-side?
body: <p>I wanna try to connect to a machine by Blazor Client-side.</p>
  
  <p>I installed the Nuget package System.Net.Sockets to achieve it.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>@page "/fetchdata"
  @inject HttpClient Http
  @using System.Net.Sockets;
  @using System.Net;
  
  &lt;h1&gt;Weather forecast&lt;/h1&gt;
  
  &lt;p&gt;This component demonstrates fetching data from the server.&lt;/p&gt;
  
  
  
  @code {    
      Socket S; 
      protected override async Task OnAfterRenderAsync(bool firstRender)
      {
          if (firstRender)
          {
              IPAddress ipAddress = IPAddress.Parse("192.168.200.111");
              IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 23);
              try
              {
                  S = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                  S.Connect(ipEndPoint);
  
                  Byte[] inBuffer = new Byte[1024];
                  S.Send(System.Text.Encoding.Default.GetBytes("PEY" + Environment.NewLine));
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex);
              }
          }
      }   
  }
  </code></pre>
  
  <p>When the breakpoint runs at </p>
  
  <pre><code>S = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  </code></pre>
  
  <p>It reports an error only with this:
  <a href="https://i.stack.imgur.com/OmEIC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OmEIC.png" alt="enter image description here"></a></p>