Asp.NET 5 listen to tcp socket

System.Net.Sockets seems to only be available in Asp.Net 4.5/4.6.

Is there a way to do this in Asp.Net 5 or are there plans to?

Jon Skeet
people
quotationmark

You just need a dependency on the System.Net.Sockets nuget package. Here's a complete example:

Code:

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;

public class Program
{
    public static void Main(string[] args)
    {
        Listen().Wait();
    }

    static async Task Listen()
    {
        var listener = new TcpListener(IPAddress.Any, 10000);
        listener.Start();
        Console.WriteLine("Waiting for a connection");
        var socket = await listener.AcceptSocketAsync();
        Console.WriteLine("Client connected!");
    }
}

Project file:

{
  "version": "1.0.0-*",
  "description": "TestVSCode Console Application",
  "dependencies": {
    "System.Net.Sockets": "4.1.0-beta-23516",
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "System.Console": "4.0.0-beta-23516"
      }
    }
  }
}

people

See more on this question at Stackoverflow