/// <summary>
 /// Start the server with given option
 /// </summary>
 /// <param name="ops">options</param>
 public void StartServer(ServerOps ops)
 {
     if (ops == null)
     {
         ops = ServerOps.defaultServerOps;
     }
     if (ops.Acceptor == null)
     {
         throw new NullReferenceException("acceptor cannot be null!");
     }
     lock (m_generalLock)
     {
         m_serverOps = ops;
     }
     Start();
 }
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (btnConnect.Text.Equals("Start"))
            {
                string port = tbPort.Text;
                tbPort.Enabled = false;
                btnConnect.Text = "Stop";
                tbSend.Enabled = true;
                btnSend.Enabled = true;
                ServerOps ops = new ServerOps(this, port,this);
                m_server.StartServer(ops);
            }
            else
            {
                tbPort.Enabled = true;
                btnConnect.Text = "Start";
                tbSend.Enabled = false;
                btnSend.Enabled = false;
                if(m_server.IsServerStarted)
                    m_server.StopServer();
            }
            

        }
 /// <summary>
 /// Default copy constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public IocpTcpServer(IocpTcpServer b)
     : base(b)
 {
     m_port      = b.m_port;
     m_serverOps = b.m_serverOps;
 }
 /// <summary>
 /// Start the server with given option
 /// </summary>
 /// <param name="ops">options</param>
 public void StartServer(ServerOps ops)
 {
     if (ops == null)
         ops = ServerOps.defaultServerOps;
     if (ops.CallBackObj == null)
         throw new NullReferenceException("callBackObj is null!");
     lock (m_generalLock)
     {
         m_serverOps = ops;
     }
     Start();
 }
 /// <summary>
 /// Default copy constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public IocpTcpServer(IocpTcpServer b)
     : base(b)
 {
     m_port = b.m_port;
     m_serverOps = b.m_serverOps;
 }
        /// <summary>
        /// Start the server and start accepting the client
        /// </summary>
        protected override void execute()
        {
            StartStatus status = StartStatus.FAIL_SOCKET_ERROR;
            try
            {
                lock (m_generalLock)
                {
                    if (IsServerStarted)
                    {
                        status = StartStatus.FAIL_ALREADY_STARTED;
                        throw new CallbackException();
                    }

                    CallBackObj = m_serverOps.CallBackObj;
                    Port = m_serverOps.Port;
                    ReceiveType = m_serverOps.ReceiveType;

                    if (Port == null || Port.Length == 0)
                    {
                        Port = ServerConf.DEFAULT_PORT;
                    }
                    m_socketMap.Clear();
                    ServerOps listenerOps = new ServerOps(this, m_serverOps.Port,true);
                    m_listener.StartServer(listenerOps);
                }

            }
            catch (CallbackException)
            {
                CallBackObj.OnServerStarted(this, status);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                if (m_listener != null)
                    m_listener.StopServer();
                m_listener = null;
                CallBackObj.OnServerStarted(this, StartStatus.FAIL_SOCKET_ERROR);
                return;
            }
            CallBackObj.OnServerStarted(this, StartStatus.SUCCESS);
        }
        /// <summary>
        /// Start the server and start accepting the client
        /// </summary>
        protected override void execute()
        {
            StartStatus status = StartStatus.FAIL_SOCKET_ERROR;
            try
            {
                lock (m_generalLock)
                {
                    if (IsServerStarted)
                    {
                        status = StartStatus.FAIL_ALREADY_STARTED;
                        throw new CallbackException();
                    }
                    Acceptor = m_serverOps.Acceptor;
                    CallBackObj = m_serverOps.CallBackObj;
                    RoomCallBackObj = m_serverOps.RoomCallBackObj;
                    Port = m_serverOps.Port;
                    ReceiveType = m_serverOps.ReceiveType;
                    MaxSocketCount = m_serverOps.MaxSocketCount;
                    MaxStreamCountPerSocket = m_serverOps.MaxStreamCountPerSocket;

                    if (Port == null || Port.Length == 0)
                    {
                        Port = ServerConf.DEFAULT_PORT;
                    }
                    lock (m_listLock)
                    {
                        m_socketMap.Clear();
                    }
                    lock (m_roomLock)
                    {
                        m_roomMap.Clear();
                    }          

                    m_listener = new IocpTcpServer();
                    ServerOps listenerOps = new ServerOps(this, m_serverOps.Port, this,null, true, MaxSocketCount);
                    m_listener.StartServer(listenerOps);
                }

            }
            catch (CallbackException)
            {
                OnParallelServerStarted(this, status);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                if (m_listener != null)
                    m_listener.StopServer();
                m_listener = null;
                OnParallelServerStarted(this, StartStatus.FAIL_SOCKET_ERROR);
                return;
            }
        }
 /// <summary>
 /// Start the server with given option
 /// </summary>
 /// <param name="ops">options</param>
 public void StartServer(ServerOps ops)
 {
     if (ops == null)
         ops = ServerOps.defaultServerOps;
     if (ops.Acceptor == null)
         throw new NullReferenceException("acceptor cannot be null!");
     lock (m_generalLock)
     {
         m_serverOps = ops;
     }
     Start();
 }