Create a Socket server from TcpListener : TcpListener « Network « C# / CSharp Tutorial






using System;
using System.IO;
using System.Net.Sockets ;

class MainClass
{
  public static void Main() 
  {
    TcpListener tcpl = new TcpListener(9999);
    tcpl.Start();

    for (;;)
    {
      Socket newSocket = tcpl.AcceptSocket();
      if (newSocket.Connected)
      {
        NetworkStream ns = new NetworkStream(newSocket);

        byte[] buf = {1,2,3,4,5,6,7,8,9};
        ns.Write(buf, 0, 9);

        ns.Flush();
        ns.Close();

      }
      newSocket.Close();
      break;

    }
  }

}








33.8.TcpListener
33.8.1.Listening for sockets
33.8.2.TcpListener Sample
33.8.3.Create a Socket server from TcpListener
33.8.4.Use NetworkStream to write to a client
33.8.5.Use TcpListener to create a Tcp server
33.8.6.Create BinaryWriter and BinaryReader from TcpListener
33.8.7.Time Server
33.8.8.Asynch Network Server