Example #1
0
        public void OnClientDisconnect(AFTCPEventParams eventParams)
        {
            if (IsConnected())
            {
                Disconnect();
            }

            net.OnDisConnect();
        }
Example #2
0
        public void OnDataReceived(AFTCPEventParams eventParams)
        {
            byte[] bytes      = eventParams.packet.bytes;
            int    bytesCount = eventParams.packet.bytesCount;
            UInt32 left       = (UInt32)bytesCount;

            net.Log("OnDataReceived:" + mnPacketSize + "|" + bytesCount);
            while (left > 0)
            {
                UInt32 copyCount = left < (ConstDefine.MAX_PACKET_LEN - mnPacketSize) ? left : (ConstDefine.MAX_PACKET_LEN - mnPacketSize);
                Array.Copy(bytes, bytesCount - left, mPacket, mnPacketSize, copyCount);
                mnPacketSize += copyCount;
                left         -= copyCount;
                OnDataReceived();
            }
        }
Example #3
0
        public void Update()
        {
            AFTCPEvent[] eventArray = null;
            lock (mxEventQueue)
            {
                eventArray = mxEventQueue.ToArray();
                mxEventQueue.Clear();
            }

            if (eventArray != null && eventArray.Length > 0)
            {
                for (int i = 0; i < eventArray.Length; i++)
                {
                    var ev = eventArray[i];
                    AFTCPEventParams eventParams = new AFTCPEventParams();
                    eventParams.eventType = ev.Type;
                    eventParams.client    = this;
                    eventParams.socket    = mxClient;
                    eventParams.packet    = ev.Data;

                    switch (ev.Type)
                    {
                    case AFTCPEventType.Connected:
                        OnClientConnect(eventParams);
                        break;

                    case AFTCPEventType.Disconnected:
                        OnClientDisconnect(eventParams);
                        break;

                    case AFTCPEventType.ConnectionRefused:
                        break;

                    case AFTCPEventType.DataReceived:
                        OnDataReceived(eventParams);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Example #4
0
 public void OnClientConnectionRefused(AFTCPEventParams eventParams)
 {
     net.Log("Client refused");
 }
Example #5
0
 public void OnClientConnect(AFTCPEventParams eventParams)
 {
     net.OnConnect();
 }