コード例 #1
0
        /// <summary>
        /// start the recieve thread
        /// </summary>
        /// <param name="cc"></param>
        void StartRxThread(ClientConnect cc)
        {
            Thread re = new Thread(rx);

            re.IsBackground = true;
            re.Start(cc);
        }
コード例 #2
0
        /// <summary>
        /// callback method for accepting a connection
        /// establish a new client,start a connection
        /// start recieving data
        /// display who is connected,how many people are connected
        /// add connecting clients to a collection
        /// </summary>
        /// <param name="ar"></param>
        void cbAccept(IAsyncResult ar)
        {
            try
            {
                ClientConnect cc = new ClientConnect();

                //accpet incoming connection requests
                cc._Client = _listener.EndAccept(ar);

                Invoke(new Action(() => { listBox1.Items.Insert(0, $"{ cc._Client.RemoteEndPoint} :Connected"); }));

                Invoke(new Action(() => { StartRxThread(cc); }));

                //add client socket to collection
                Listcc.Add(cc);

                Invoke(new Action(() => { label1.Text = $"Clients: {Listcc.Count}"; }));
                _listener.BeginAccept(cbAccept, null);
            }
            catch (Exception exc)
            {
                Invoke(new Action(() => { listBox1.Items.Insert(0, $"cbAccept:exception raised : {exc.Message}"); }));
            }
        }