using System; using System.Net; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080); listener.Start(); Console.WriteLine("Server started on port 8080."); } }
using System; using System.Net; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpListener listener = new TcpListener(IPAddress.Any, 8080); listener.Start(); Console.WriteLine("Server started on port 8080."); while (true) { TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Client connected."); } } }This example creates a `TcpListener` object that listens for incoming connections on any available IP address and port `8080`. The `Start()` method is then called to start listening for incoming connections. If successful, it prints a message indicating that the server has started on port `8080`. The `while` loop then waits for incoming connections using the `AcceptTcpClient()` method. If a connection is made, it prints a message indicating that the client is connected. Package/Library: `System.Net.Sockets` is a built-in library in C#. No additional package is required.