public partial class Form1 : Form
    {
        private IPEndPoint MyServer;
        private Socket sock;
        private Thread myThread;
        private Socket[] clientsock;
        private int clientnum;
        private byte[] buffer;
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            MyServer = new IPEndPoint(IPAddress.Any, 10000);
            sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Bind(MyServer);
            sock.Listen(10);
            myThread = new Thread(recvaccept);
            myThread.Start();
            CheckForIllegalCrossThreadCalls = false;
            clientsock = new Socket[65535];
            clientnum = 0;
            buffer = new byte[65535]; 
        }        private void recvaccept()
        {
            
  
                while (true)
                {
                    clientsock[clientnum] = sock.Accept();
                    clientsock[clientnum].BeginReceive(buffer, 0, buffer.Length, 0, new AsyncCallback(ReceiveCallback), clientsock[clientnum]);
                    clientlist.Items.Add(clientsock[clientnum].RemoteEndPoint.ToString());
                    clientnum++;
                }            
        }       
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            sock.Close();
            myThread.Abort();
        }
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                Socket a = (Socket)ar.AsyncState;
                int read = a.EndReceive(ar);
                //clientlist.Items.Add(Encoding.ASCII.GetString(buffer,0,read));
                for (int i = 0; i < clientnum; i++)
                {
                    if (clientsock[i].Connected)
                    {                     
                        clientsock[i].Send(buffer, 0, read, 0);
                    }
                }
                a.BeginReceive(buffer, 0, buffer.Length, 0, new AsyncCallback(ReceiveCallback), a);
            }
            catch
            {}           
        } 
    }