Exemple #1
0
        // 接受连接
        private void SocketAccept(IAsyncResult result)
        {
            // 判断并设置工作标识
            if (!this.Working)
            {
                return;
            }

            //获取响应的通讯组件
            Socket client = _socket.EndAccept(result);

            try {
                //处理下一个客户端连接
                _socket.BeginAccept(new AsyncCallback(SocketAccept), _socket);

                //新增一个实体
                ServerEntity wsc = new ServerEntity(this, client);
                this.Entities.Add(wsc);
            } catch (Exception ex) {
                //调试输出错误信息
                Debug.WriteLine("-> Error:\r\n" + ex.ToString());
            }
        }
Exemple #2
0
        /// <summary>
        /// 宿主运行服务
        /// </summary>
        public void Run()
        {
            // 判断并设置工作标识
            if (this.Working)
            {
                return;
            }
            this.Working = true;

            // 监听基础网络通讯组件
            _socket.Listen(10);

            // 接受连接
            while (this.Working)
            {
                //接受一个连接
                Socket socket = _socket.Accept();

                //新增一个实体
                ServerEntity wsc = new ServerEntity(this, socket);
                this.Entities.Add(wsc);
            }
        }