Example #1
0
        private void Listen()
        {
            int i = 0;

            try
            {
                for (i = 0; i <= MaxConnection; ++i)
                {
                    clientSocket.Add(Accept());
                    OnConnection.BeginInvoke(clientSocket[i].RemoteEndPoint.ToString(), null, null);
                    clientSocket[i].Blocking          = true;
                    clientSocket[i].SendBufferSize    = _SendBufferSize;
                    clientSocket[i].ReceiveBufferSize = _ReceiveBufferSize;

                    Thread t = new Thread(Received);
                    t.IsBackground = true;
                    t.Name         = i.ToString();
                    t.Priority     = ThreadPriority.Lowest;
                    t.Start();
                }
            }
            catch
            {
                Error_Message = "服务器已停止";
                OnError.BeginInvoke(Error_Message, null, null);
                CloseSocket(i);
            }
        }
Example #2
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <returns>成功返回TRUE</returns>
        public bool ConnectionServer()
        {
            try
            {
                IPEndPoint _ip = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), port);
                this.Connect(_ip);
                this.SendBufferSize    = _SendBufferSize;
                this.ReceiveBufferSize = _ReceiveBufferSize;

                OnConnection.BeginInvoke(null, null);
                Thread t = new Thread(Receive);//数据返回监视
                t.IsBackground = true;
                t.Priority     = ThreadPriority.Lowest;
                t.Start();
                return(true);
            }
            catch (Exception e)
            {
                Error_Message = e.Message;
                OnError(e.Message);
                return(false);
            }
        }