Exemplo n.º 1
0
        internal void ProcessPackets(string Packet)
        {
            try
            {
                ClientMessage Mess = new ClientMessage(Packet);
                Out.Write("[" + Mess.Header() + "] » ", ConsoleColor.Gray, "");

                if (RequestPacket[Mess.Header()] == null)
                {
                    Out.Write("No Registrado", ConsoleColor.DarkRed, "");
                    Out.WriteBlank();
                }
                else
                {
                    Out.Write("Registrado", ConsoleColor.DarkGreen, "");
                    Out.WriteBlank();
                    User.ActualClientMessage = Mess;
                    User.ActualPacket = Packet;
                    RequestPacket[Mess.Header()].Invoke();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Azure ha encontrado un error en el código: " + e.ToString());
            }
        }
Exemplo n.º 2
0
        private void ReceivedData(IAsyncResult iAr)
        {
            try
            {
                int bytesReceived = new int();

                try
                {
                    bytesReceived = ClientSocket.EndReceive(iAr);
                }
                catch
                {
                    Close();
                    return;
                }

                string ReceiveData = System.Text.Encoding.Default.GetString(dataBuffer, 0, bytesReceived);
                //if (ReceiveData.StartsWith("<policy-file-request/>"))
                if (ReceiveData.Contains("<policy-file-request/>"))
                {
                    string Data = "<?xml version=\"1.0\"?>" + "\r\n" + "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">" + "\r\n" + "<cross-domain-policy>" + "\r\n" + "   <allow-access-from domain=\"*\" to-ports=\"1-65535\" />" + "\r\n" + "</cross-domain-policy>\0";
                    byte[] dataBytes = System.Text.Encoding.Default.GetBytes(Data);
                    sendData(dataBytes);
                    Close();
                }
                else
                {
                    while (ReceiveData.Length > 0)
                    {
                        ClientMessage Message = new ClientMessage(ReceiveData);
                        if (ReceiveData.Length > 1)
                        {
                            Handler.ProcessPackets(ReceiveData.Substring(0, 4 + Message.Lenght()));
                            ReceiveData = ReceiveData.Remove(0, 4 + Message.Lenght());
                        }
                    }
                }
            }
            catch
            {
                Close();
            }
            finally
            {
                WaitForData();
            }
        }