예제 #1
0
        public void BeginReceiveMessage(ConnectControl connect)
        {
            connect.socket.BeginReceive(connect.buffer, connect.bufferCount, connect.BUffRemain(), SocketFlags.None, (asyncResult) =>
            {
                ConnectControl connectControl = null;

                connectControl = asyncResult.AsyncState as ConnectControl;
                lock (connectControl)
                {
                    try
                    {
                        int count = connectControl.socket.EndReceive(asyncResult);
                        if (count == 0)
                        {
                            connectControl.Close();
                            return;
                        }

                        connectControl.bufferCount += count;
                        ProcessData(connectControl);

                        BeginReceiveMessage(connectControl);
                    }
                    catch (Exception e)
                    {
                        if (connectControl != null)
                        {
                            connectControl.Close();
                        }

                        //throw e;
                    }
                }
            }, connect);
        }
예제 #2
0
        public void Close()
        {
            for (int i = 0; i < connects.Length; i++)
            {
                ConnectControl connect = connects[i];

                if (connect == null)
                {
                    continue;
                }
                if (!connect.isUse)
                {
                    continue;
                }

                lock (connect)
                {
                    connect.Close();
                }
            }
        }
        private void HeartBeat()
        {
            long timeNow = TimeHelper.GetTimeStamp();

            for (int i = 0; i < controlTerminal.connects.Length; i++)
            {
                ConnectControl connect = controlTerminal.connects[i];
                if (connect == null)
                {
                    continue;
                }
                if (!connect.isUse)
                {
                    continue;
                }
                if (connect.lastTickTime < timeNow - heartBeatTime)
                {
                    lock (connect)
                    {
                        connect.Close();
                    }
                }
            }
        }