Example #1
0
        void Accept_Callback(IAsyncResult AR)
        {
            Socket ClientSocket;

            try
            {
                ClientSocket = serverSocket.EndAccept(AR);

                Client_ID++;
                Client_Info cl = new Client_Info();
                cl.clientSocket = ClientSocket;
                cl.CLientID     = Client_ID;
                clientSockets_List.Add(cl);
                BeginInvoke(new MethodInvoker(() => List_Client.Items.Add("Client " + Client_ID, CheckState.Unchecked)));


                ClientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, Receive_Callback, ClientSocket);

                serverSocket.BeginAccept(Accept_Callback, null);
            }
            catch (ObjectDisposedException)
            {
                MessageBox.Show("Server Error");
            }
        }
Example #2
0
        public void Accept_Client()
        {
            while (true)
            {
                Socket newClient = serverSocket.Accept();
                CLientID++;
                Client_Info client = new Client_Info();
                client.clientSocket = newClient;
                client.CLientID     = CLientID;
                clientList.Add(client);
                List_Clients.Items.Add("Client " + CLientID, CheckState.Unchecked);

                try
                {
                    foreach (Client_Info clientt in clientList)
                    {
                        clientt.clientSocket.Send(Encoding.ASCII.GetBytes("\nServer: Client " + CLientID + " connected\n"));
                    }
                }
                catch (Exception)
                {
                    string s = "do nothing";
                }



                Thread t = new Thread(new ThreadStart(() => ReadMessage(newClient)));
                t.Start();
            }
        }