Ejemplo n.º 1
0
        public void OnLeave(T remoteClient)
        {
            IRemoteClient client = (IRemoteClient)remoteClient;

            lock (sync_obj)
            {
                RemoteClients.Remove(client.GetRemoteID());
            }
            RemotePool.FreeRemotePool(client.GetRemoteID());
        }
Ejemplo n.º 2
0
        public void OnRecv(T remoteClient, byte[] buffer, int len)
        {
            IRemoteClient client = (IRemoteClient)remoteClient;

            if (client.GetRemoteID() == RemoteID.Remote_None)
            {
                // Connect스레드가 다를경우 조금 기다려주도록 하자
                for (int i = 0; i < WaitDelayRecvThreadCount; i++)    // 20일경우 100 * 20 즉 2000밀리세컨드 -> 최대 2초까지 기다려준다
                {
                    System.Threading.Thread.Sleep(100);
                    if (client.GetRemoteID() != RemoteID.Remote_None)
                    {
                        break;
                    }
                }

                // 그래도 할당안됬다면?
                if (client.GetRemoteID() == RemoteID.Remote_None)
                {
                    // 이경우는 연결이벤트 처리가 아직안된경우임
                    if (message_handler != null)
                    {
                        message_handler(MsgType.Error, "remoteID 할당이 안되었음.");
                    }
                }
            }

            CRecvedMsg recved_msg = new CRecvedMsg();

            try
            {
                CPackOption packOption = new CPackOption();
                CMessage    MsgBuffer  = new CMessage(buffer, 0, len);
                recved_msg.From(
                    client.GetRemoteID(),
                    MsgBuffer,
                    MsgBuffer.ReadStart(out packOption),
                    packOption
                    );

                // 예외발생 test
                //string a = "aa";
                //int.Parse(a);
            }
            catch (Exception e)
            {
                if (message_handler != null)
                {
                    message_handler(MsgType.Warning, string.Format("{0} OnPackException: {1}",
                                                                   client.Address().ToString(),
                                                                   e.Message));
                }
                client.Disconnect();
                return;
            }

            string msg = OnPacket(recved_msg);

            if (msg != string.Empty)
            {
                if (message_handler != null)
                {
                    message_handler(MsgType.Warning, string.Format("{0} {1}", client.Address().ToString(), msg));
                }
                client.Disconnect();
            }
        }