コード例 #1
0
ファイル: frmServer.cs プロジェクト: nditz/TMS-SERVER
        public bool RegisterClient(SessionClass Session, System.Threading.Thread Thread)
        {
            int nIndex = 0;
            int nMaxClients = 0;
            nMaxClients = Int32.Parse(strMaxConnections);
            if (nMaxClients > 0 & ActiveClients >= nMaxClients)
            {
                return false;
            }
            Monitor.Enter(Client);
            for (nIndex = 0; nIndex < LastClient; nIndex++)
            {
                if (Client[nIndex].Session != null) continue;
                Client[nIndex].Session = Session;
                Client[nIndex].Thread = Thread;
                ActiveClients = ActiveClients + 1;
                SetServerStatus(ActiveClients.ToString() + " clients connected to server");
                Monitor.Exit(Client);
                return true;
            }
            Monitor.Exit(Client);
            var NewClient = new SessionInfo[LastClient + 1];
            System.Array.Copy(Client, NewClient, Math.Min(Client.Length, NewClient.Length));
            Client = NewClient;
            Client[LastClient].Session = Session;
            Client[LastClient].Thread = Thread;

            LastClient++;
            ActiveClients++;

            SetServerStatus(ActiveClients.ToString() + " clients connected to server");
            return true;
        }
コード例 #2
0
ファイル: frmServer.cs プロジェクト: nditz/TMS-SERVER
 //protected override void Dispose(bool disposing)
 //{
 //    if (disposing)
 //    {
 //        if (!((components == null)))
 //        {
 //            components.Dispose();
 //        }
 //    }
 //    base.Dispose(disposing);
 //}
 private void Socket_OnAccept(object sender, SocketTools.SocketWrench.AcceptEventArgs e)
 {
     SessionClass oSession = null;
     System.Threading.Thread oThread = null;
     LastSessionId++;
     oSession = new SessionClass();
     oSession.Server = this;
     oSession.Handle = e.Handle;
     oThread = new System.Threading.Thread(new System.Threading.ThreadStart(oSession.ThreadMain));
     oThread.SetApartmentState(ApartmentState.STA);
     oThread.Name = "Session" + LastSessionId;
     oThread.Start();
 }