Пример #1
0
        /// <summary>
        /// 停止侦听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonListenStop_Click(object sender, EventArgs e)
        {
            TcpLessoner listener = (TcpLessoner)comboBoxSocketConnected.SelectedItem;

            tcpServerBindingSource.Remove(listener);
            listener.Stop();
        }
Пример #2
0
        /// <summary>
        /// 开始侦听端口
        /// </summary>
        /// <param name="port">端口号</param>
        /// <param name="maxNumAccepts">允许的最大连接数</param>
        /// <returns></returns>
        public TcpLessoner NewTcpLessoner(int port, int maxNumberConnections)
        {
            TcpLessoner server = new TcpLessoner(components);

            server.MaxNumberConnections = maxNumberConnections;
            server.ConnectionBuilded   += (object sender, ConnectionBuildedEventArgs e) => { if (ConnectionBuilded != null)
                                                                                             {
                                                                                                 ConnectionBuilded(this, e);
                                                                                             }
            };
            server.Start(port);
            return(server);
        }