Ejemplo n.º 1
0
        private void BeginConnection(IAsyncResult result)
        {
            if (!Core.isRunning || mListener.Server.IsBound)
            {
                return;
            }

            try
            {
                TcpClient _tcpClient = mListener.EndAcceptTcpClient(result);
                lock (Core.ConnectionList)
                    Core.ConnectionList.Add(new BSConnection(++SessionCount, _tcpClient));
            }
            catch (Exception ex)
            {
                FrmMain.Enqueue(ex);
            }
            finally
            {
                if (Core.isRunning && mListener.Server.IsBound)
                {
                    mListener.BeginAcceptTcpClient(BeginConnection, null);
                }
            }
        }
Ejemplo n.º 2
0
        private void ThreadLoop(BSThreadInfo Info)
        {
            Info.Stop = false;
            long InitTime = Time;

            try
            {
            }
            catch (Exception ex)
            {
                if (ex is ThreadInterruptedException)
                {
                    return;
                }

                FrmMain.Enqueue(ex);
                File.AppendAllText(@".\Error.txt", string.Format("[{0}] {1}{2}", Now, ex, Environment.NewLine));
            }
        }
Ejemplo n.º 3
0
        public BSConnection(int sessionID, TcpClient client)
        {
            SessionID = sessionID;
            IPAddress = client.Client.RemoteEndPoint.ToString().Split(':')[0];

            bool _detected = false;

            foreach (BSConnection _conn in Core.ConnectionList)
            {
                if (_conn.IPAddress == IPAddress)
                {
                    FrmMain.Enqueue("Concurrent Connection Detected. (" + IPAddress + ")");
                    _detected = true;
                    break;
                }
            }

            if (_detected)
            {
                return;
            }

            FrmMain.Enqueue(IPAddress + ", Connected.");

            mClient         = client;
            mClient.NoDelay = true;

            ConnectedTime = Core.Time;
            TimeoutTime   = ConnectedTime + Settings.ConnectionTimeout;

            mReceiveList = new ConcurrentQueue <BSPacket>();
            mSendList    = new Queue <BSPacket>();
            mRetryList   = new Queue <BSPacket>();

            Connected = true;
            BeginReceive();
        }
Ejemplo n.º 4
0
        private void WorkLoop()
        {
            try
            {
                Time = _stopWatch.ElapsedMilliseconds;

                if (!Settings.Multithreaded)
                {
                    Settings.ThreadLimit = 1;
                }

                mThread     = new Thread[Settings.ThreadLimit];
                mThreadInfo = new BSThreadInfo[Settings.ThreadLimit];

                for (int a = 0; a < mThreadInfo.Length; a++)
                {
                    mThreadInfo[a] = new BSThreadInfo(a);
                }

                // Server System Boot
                //
                //
                StartCore();

                if (Settings.Multithreaded)
                {
                    for (int a = 0; a < mThreadInfo.Length; a++)
                    {
                        mThread[a] = new Thread(() => ThreadLoop(mThreadInfo[a]));
                        mThread[a].IsBackground = true;
                        mThread[a].Start();
                    }
                }

                // Server Network Boot
                //
                //

                try
                {
                    while (isRunning) // Core Thread Loop
                    {
                        Time = _stopWatch.ElapsedMilliseconds;
                    }
                }
                catch (Exception ex)
                {
                    FrmMain.Enqueue(ex);

                    var _st    = new StackTrace(ex, true);
                    var _frame = _st.GetFrame(0);
                    var _line  = _frame.GetFileLineNumber();

                    File.AppendAllText(@".\Error.txt", string.Format("[{0}] {1} at line {2}{3}", Now, ex, _line, Environment.NewLine));
                }

                // Server System Stop
                //
                //
            }
            catch (Exception ex)
            {
                FrmMain.Enqueue(ex);

                var _st    = new StackTrace(ex, true);
                var _frame = _st.GetFrame(0);
                var _line  = _frame.GetFileLineNumber();

                File.AppendAllText(@".\Error.txt", string.Format("[{0}] {1} at line {2}{3}", Now, ex, _line, Environment.NewLine));
            }
        }