Ejemplo n.º 1
0
        public Coming HaCo(byte[] data, int size, Socket udp, EndPoint cep)
        {
            byte[] ET      = new byte[4];
            byte[] message = new byte[size - 4];

            Array.Copy(data, 0, ET, 0, 4);

            int EventType = BitConverter.ToInt32(ET, 0);

            Array.Copy(data, 4, message, 0, message.Length);

            if (EventType > 3000)
            {
                Coming co = HaCo2(data, size, udp, cep);
                return(co);
            }
            else
            {
                string _message = Encoding.UTF8.GetString(message);

                Coming c = new Coming();
                c.EventType = EventType;
                c.message   = _message;
                c.cep       = cep;
                c._sock     = udp;
                c.Address   = ((IPEndPoint)cep).Address.ToString();
                c.port      = ((IPEndPoint)cep).Port;
                c.data      = data;

                return(c);
            }
        }
Ejemplo n.º 2
0
        private void p2001(Coming comi)
        {
            string message = comi.message;

            string[] messages = message.Split(',');

            if (messages[1].Length > 10)
            {
                if (Agent.clients.ContainsKey(messages[1]))
                {
                    foreach (KeyValuePair <string, Coming> client in Agent.clients)
                    {
                        if (client.Value.id.Equals(messages[1], StringComparison.CurrentCultureIgnoreCase))
                        {
                            DataHandle Handle = new DataHandle();
                            byte[]     data   = Handle.HaSe(1006, client.Value.id + "," + client.Value.NaTType + "," + client.Value.cep + "," + client.Value.Address + "," + client.Value.port);
                            comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);

                            byte[] data2 = Handle.HaSe(1008, comi.id + "," + comi.NaTType + "," + comi.cep + "," + comi.Address + "," + comi.port);
                            client.Value._sock.BeginSendTo(data2, 0, data2.Length, SocketFlags.None, client.Value.cep, new AsyncCallback((async) => { }), client.Value._sock);
                        }
                    }
                }
                else
                {
                    DataHandle Handle = new DataHandle();
                    byte[]     data   = Handle.HaSe(1007, "");
                    comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                }
            }
            else
            {
                //WAITING FOR REQ.
            }
        }
        public Coming HaCo(byte[] data, int size, Socket udp, EndPoint cep)
        {
            byte[] ET = new byte[4];
            byte[] message = new byte[size - 4];

            Array.Copy(data, 0, ET, 0, 4);

            int EventType = BitConverter.ToInt32(ET, 0);
            Array.Copy(data, 4, message, 0, message.Length);

            if (EventType > 3000)
            {
                Coming co = HaCo2(data, size, udp, cep);
                return co;
            }
            else
            {
                string _message = Encoding.UTF8.GetString(message);

                Coming c = new Coming();
                c.EventType = EventType;
                c.message = _message;
                c.cep = cep;
                c._sock = udp;
                c.Address = ((IPEndPoint)cep).Address.ToString();
                c.port = ((IPEndPoint)cep).Port;
                c.data = data;

                return c;
            }
        }
        public Coming HaCo(byte[] data,int size , Socket udp,EndPoint cep)
        {
            ("LRECIEVE").p2pDEBUG(); //TODO : LRECIEVE

            byte[] ET = new byte[4];
            byte[] message = new byte[size - 4];

            Array.Copy(data, 0, ET, 0, 4);
            Array.Copy(data, 4, message, 0, message.Length);

            int EventType = BitConverter.ToInt32(ET, 0);
            string _message = Encoding.UTF8.GetString(message);

            Coming c = new Coming();
            string[] messages = _message.Split(',');
            c.id = messages[0];
            c.EventType = EventType;
            c.message = _message;
            c.cep = cep;
            c._sock = udp;
            c.Address = ((IPEndPoint)cep).Address.ToString();
            c.port = ((IPEndPoint)cep).Port;

            return c;
        }
        public void RecordAgent()
        {
            #region CLIENT RECORD

            if (!File.Exists(Generate.xmlPath))
                return;

            XmlDocument xmld = new XmlDocument();
            try { xmld.Load(Generate.xmlPath); }
            catch { Thread.Sleep(50); xmld.Load(Generate.xmlPath); }
            foreach (XmlElement xmle in xmld.GetElementsByTagName("clients"))
            {
                Coming c = new Coming();
                c.id = xmle["id"].InnerText;
                c.lep = xmle["lep"].InnerText;
                c.macAddress = xmle["macAddress"].InnerText;
                c.licence = xmle["licence"].InnerText;
                c.Session = Convert.ToInt32(xmle["Session"].InnerText);
                c.port = Convert.ToInt32(xmle["port"].InnerText);
                c.Address = xmle["Address"].InnerText;
                c.cep = new IPEndPoint(IPAddress.Parse(c.Address), c.port);

                Agent.clients.Add(c.id, c);
            }
            try { xmld.Save(Generate.xmlPath); }
            catch { Thread.Sleep(50); xmld.Save(Generate.xmlPath); }

            Generate.isFirst = false;
            ("SERVER WORKING FIRST TIME & TRANSFERRED XML DATA TO Agent.clients").p2pDEBUG();
            #endregion
        }
Ejemplo n.º 6
0
        private void p2000(Coming comi)
        {
            foreach (KeyValuePair <string, Coming> clie in Agent.clients)
            {
                ("L1006").p2pDEBUG(); //TODO : L1006
                if (clie.Key == comi.id)
                {
                    if (comi.port == clie.Value.port)
                    {
                        //NaT CONIC

                        ("L1007").p2pDEBUG(); //TODO : L1006

                        var c = from n in Agent.clients where n.Value.id == comi.id select n;
                        foreach (KeyValuePair <string, Coming> a in c)
                        {
                            a.Value.NaTType = 1;
                        }

                        DataHandle Handle = new DataHandle();
                        byte[]     data   = Handle.HaSe(1004, "NaT CONIC");
                        comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                    }
                    else
                    {
                        //NaT SYMETRIC
                        ("L1008").p2pDEBUG(); //TODO : L1007
                        DataHandle Handle = new DataHandle();
                        byte[]     data   = Handle.HaSe(1005, "NaT SYMETRIC");
                        comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public Coming HaCo(byte[] data, int size, Socket udp, EndPoint cep)
        {
            ("LRECIEVE").p2pDEBUG(); //TODO : LRECIEVE

            byte[] ET      = new byte[4];
            byte[] message = new byte[size - 4];

            Array.Copy(data, 0, ET, 0, 4);
            Array.Copy(data, 4, message, 0, message.Length);

            int    EventType = BitConverter.ToInt32(ET, 0);
            string _message  = Encoding.UTF8.GetString(message);

            Coming c = new Coming();

            string[] messages = _message.Split(',');
            c.id        = messages[0];
            c.EventType = EventType;
            c.message   = _message;
            c.cep       = cep;
            c._sock     = udp;
            c.Address   = ((IPEndPoint)cep).Address.ToString();
            c.port      = ((IPEndPoint)cep).Port;

            return(c);
        }
Ejemplo n.º 8
0
        public Process(Coming comi)
        {
            switch (comi.EventType)
            {
            case 1000:
                p1000(comi);
                break;

            case 2000:
                p2000(comi);
                break;

            case 2001:
                p2001(comi);
                break;
            }
        }
Ejemplo n.º 9
0
        public Process(Coming comi)
        {
            switch (comi.EventType)
            {
                case 1000:
                    p1000(comi);
                    break;

                case 2000:
                    p2000(comi);
                    break;

                case 2001:
                    p2001(comi);
                    break;
            }
        }
Ejemplo n.º 10
0
        internal void Rect(Socket udp)
        {
            DataHandle Hand   = new DataHandle();
            Thread     thread = new Thread(new ThreadStart(() =>
            {
                byte[] data    = new byte[20480];
                cepb           = new IPEndPoint(IPAddress.Any, 0);
                int size       = udp.ReceiveFrom(data, ref cepb);
                Thread threada = new Thread(new ThreadStart(() =>
                {
                    Coming c          = Hand.HaCo(data, size, udp, cepb);
                    Protocol protocol = new Protocol(c);
                }));
                threada.Start();
                Rect(udp);
            }));

            thread.Start();
        }
Ejemplo n.º 11
0
        internal void ComingData(Coming comi)
        {
            switch (comi.EventType)
            {
                case 1000:
                    ("L1003").p2pDEBUG(); //TODO : L1003
                    Process proca = new Process(comi);
                    break;

                case 2000:
                    ("L1005").p2pDEBUG(); //TODO : L1005
                    Process procb = new Process(comi);
                    break;

                case 2001:
                    ("L1009").p2pDEBUG(); //TODO : L1005
                    Process procc = new Process(comi);
                    break;
            }
        }
Ejemplo n.º 12
0
        internal void ComingData(Coming comi)
        {
            switch (comi.EventType)
            {
            case 1000:
                ("L1003").p2pDEBUG();     //TODO : L1003
                Process proca = new Process(comi);
                break;

            case 2000:
                ("L1005").p2pDEBUG();     //TODO : L1005
                Process procb = new Process(comi);
                break;

            case 2001:
                ("L1009").p2pDEBUG();     //TODO : L1005
                Process procc = new Process(comi);
                break;
            }
        }
Ejemplo n.º 13
0
        public clients Record(ref Coming c)
        {
            string[] _messages = c.message.Split(',');
            c.id = _messages[0];
            c.licence = _messages[1];
            c.macAddress = _messages[2];
            c.lep = _messages[3];

            clients _clients = new clients();
            _clients.Address = c.Address;
            _clients.EventType = c.EventType;
            _clients.id = c.id;
            _clients.lep = c.lep;
            _clients.licence = c.licence;
            _clients.macAddress = c.macAddress;
            _clients.message = c.message;
            _clients.port = c.port;
            _clients.Session = c.Session;
            _clients.cep = c.cep.ToString();

            return _clients;
        }
Ejemplo n.º 14
0
        private void Recb(Socket udpb)
        {
            DataHandle Hand = new DataHandle();
            Protocol   prot = new Protocol();

            Thread thread = new Thread(new ThreadStart(() =>
            {
                byte[] data = new byte[20480];
                cepb        = new IPEndPoint(IPAddress.Any, 0);
                int size    = udpb.ReceiveFrom(data, ref cepb);
                ("L1004").p2pDEBUG(); //TODO : L1004
                Thread threada = new Thread(new ThreadStart(() =>
                {
                    Coming comi = Hand.HaCo(data, size, udpb, cepb);
                    prot.ComingData(comi);
                }));
                threada.Start();
                Recb(udpb);
            }));

            thread.Start();
        }
Ejemplo n.º 15
0
        public Coming HaCo2(byte[] data, int size, Socket udp, EndPoint cep)
        {
            byte[] ET = new byte[4];
            byte[] DS = new byte[4];

            Array.Copy(data, 0, ET, 0, 4);
            Array.Copy(data, 4, DS, 0, 4);

            int messagesize = BitConverter.ToInt32(DS, 0);

            byte[] message = new byte[messagesize];

            Array.Copy(data, 8, message, 0, messagesize);

            int das = (size - (8 + messagesize));

            byte[] _data = new byte[das];

            Array.Copy(data, (8 + messagesize), _data, 0, das);

            int    EventType = BitConverter.ToInt32(ET, 0);
            string _message  = Encoding.UTF8.GetString(message);

            Coming c = new Coming();

            c.EventType = EventType;
            c.message   = _message;
            c.cep       = cep;
            c._sock     = udp;
            c.Address   = ((IPEndPoint)cep).Address.ToString();
            c.port      = ((IPEndPoint)cep).Port;
            c.data      = _data;
            c.AgentID   = _message;

            return(c);
        }
Ejemplo n.º 16
0
        private void p1000(Coming c)
        {
            Recording recording = new Recording();
            clients _clients = recording.Record(ref c);
            DataHandle Handle = new DataHandle();

            if (Agent.clients.ContainsKey(c.id))
            {
                #region XML && CLIENT UPLOADED

                XmlDocument xmld = new XmlDocument();
                try { xmld.Load(xmlPath); }
                catch { Thread.Sleep(50); xmld.Load(xmlPath); }
                foreach (XmlElement xmle in xmld.GetElementsByTagName("clients"))
                {
                    if (xmle["id"].InnerText.Equals(_clients.id, StringComparison.CurrentCultureIgnoreCase))
                    {
                        xmle["id"].InnerText = _clients.id;
                        xmle["lep"].InnerText = _clients.lep;
                        xmle["macAddress"].InnerText = _clients.macAddress;
                        xmle["licence"].InnerText = _clients.licence;
                        xmle["Session"].InnerText = (Convert.ToInt32(xmle["Session"].InnerText) + 1).ToString();
                        xmle["port"].InnerText = _clients.port.ToString();
                        xmle["Address"].InnerText = _clients.Address;
                        xmle["cep"].InnerText = _clients.cep;
                    }
                }
                try { xmld.Save(xmlPath); }
                catch { Thread.Sleep(50); xmld.Save(xmlPath); }

                #endregion
                #region CLIENT CONNECTED AGAIN REPLACE PROPERTIES

                foreach (KeyValuePair<string, Coming> client in Agent.clients)
                {
                    if (client.Key.Equals(c.id, StringComparison.CurrentCultureIgnoreCase))
                    {

                        #region MAC ADDRESS DIFFERENT
                        if (!client.Value.macAddress.Equals("NOT"))
                        {
                            if (!client.Value.macAddress.Equals(c.macAddress))
                            {
                                byte[] data = Handle.HaSe(1001, "ID SAVED BEFORE FOR DIFFERENT CLIENT");
                                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                                return;
                            }
                        }
                        #endregion
                        #region CLIENT UPDATE
                        client.Value.lep = c.lep;
                        client.Value._sock = c._sock;
                        client.Value.Address = c.Address;
                        client.Value.cep = c.cep;
                        client.Value.EventType = c.EventType;
                        client.Value.licence = c.licence;
                        client.Value.macAddress = c.macAddress;
                        client.Value.message = c.message;
                        client.Value.port = c.port;
                        #endregion
                        byte[] d = Handle.HaSe(1002, "CLIENT ALREADY IN THE LIST");
                        c._sock.BeginSendTo(d, 0, d.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                    }
                }

                #endregion
            }
            else
            {
                Agent.clients.Add(c.id, c);
                if (!File.Exists(xmlPath))
                {
                    #region WRITE DOC
                    XmlTextWriter writer = new XmlTextWriter(xmlPath, Encoding.UTF8);
                    writer.Formatting = Formatting.Indented;
                    writer.WriteComment("Saved Clients list");
                    writer.WriteStartElement("Clients");
                    writer.WriteEndElement();
                    writer.Close();
                    #endregion
                }
                #region XML SAVE
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Load(xmlPath);
                }

                XmlNode client = doc.DocumentElement;
                XmlElement element = doc.CreateElement("clients");

                XmlNode node1 = doc.CreateElement("id");
                node1.InnerText = _clients.id;
                element.AppendChild(node1);

                XmlNode node2 = doc.CreateElement("licence");
                node2.InnerText = _clients.licence;
                element.AppendChild(node2);

                XmlNode node3 = doc.CreateElement("macAddress");
                node3.InnerText = _clients.macAddress;
                element.AppendChild(node3);

                XmlNode node4 = doc.CreateElement("Address");
                node4.InnerText = _clients.Address;
                element.AppendChild(node4);

                XmlNode node5 = doc.CreateElement("port");
                node5.InnerText = _clients.port.ToString();
                element.AppendChild(node5);

                XmlNode node6 = doc.CreateElement("cep");
                node6.InnerText = _clients.cep;
                element.AppendChild(node6);

                XmlNode node7 = doc.CreateElement("lep");
                node7.InnerText = _clients.lep;
                element.AppendChild(node7);

                XmlNode node8 = doc.CreateElement("Session");
                node8.InnerText = "1";
                element.AppendChild(node8);

                XmlNode node9 = doc.CreateElement("message");
                node9.InnerText = _clients.message;
                element.AppendChild(node9);

                client.AppendChild(element);
                try
                {
                    doc.Save(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Save(xmlPath);
                }
                #endregion
                byte[] data = Handle.HaSe(1003, "CLIENT RECORDED SUCCESFULY");
                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
            }
        }
Ejemplo n.º 17
0
        private void p2001(Coming comi)
        {
            string message = comi.message;
            string[] messages = message.Split(',');

            if (messages[1].Length > 10)
            {
                if (Agent.clients.ContainsKey(messages[1]))
                {
                    foreach (KeyValuePair<string, Coming> client in Agent.clients)
                    {
                        if (client.Value.id.Equals(messages[1], StringComparison.CurrentCultureIgnoreCase))
                        {
                            DataHandle Handle = new DataHandle();
                            byte[] data = Handle.HaSe(1006, client.Value.id + "," + client.Value.NaTType + "," + client.Value.cep + "," + client.Value.Address + "," + client.Value.port);
                            comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);

                            byte[] data2 = Handle.HaSe(1008, comi.id + "," + comi.NaTType + "," + comi.cep + "," + comi.Address + "," + comi.port);
                            client.Value._sock.BeginSendTo(data2, 0, data2.Length, SocketFlags.None, client.Value.cep, new AsyncCallback((async) => { }), client.Value._sock);
                        }
                    }
                }
                else
                {
                    DataHandle Handle = new DataHandle();
                    byte[] data = Handle.HaSe(1007, "");
                    comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                }
            }
            else
            {
                //WAITING FOR REQ.
            }
        }
Ejemplo n.º 18
0
        private void p2000(Coming comi)
        {
            foreach (KeyValuePair<string, Coming> clie in Agent.clients)
            {
                ("L1006").p2pDEBUG(); //TODO : L1006
                if (clie.Key == comi.id)
                {
                    if (comi.port == clie.Value.port)
                    {
                        //NaT CONIC

                        ("L1007").p2pDEBUG(); //TODO : L1006

                        var c = from n in Agent.clients where n.Value.id == comi.id select n;
                        foreach (KeyValuePair<string, Coming> a in c) { a.Value.NaTType = 1; }

                        DataHandle Handle = new DataHandle();
                        byte[] data = Handle.HaSe(1004, "NaT CONIC");
                        comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                    }
                    else
                    {
                        //NaT SYMETRIC
                        ("L1008").p2pDEBUG(); //TODO : L1007
                        DataHandle Handle = new DataHandle();
                        byte[] data = Handle.HaSe(1005, "NaT SYMETRIC");
                        comi._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, comi.cep, new AsyncCallback((async) => { }), comi._sock);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public Protocol(Coming comi)
        {
            switch (comi.EventType)
            {
                case 1001:
                    FirstArrived();
                    break;

                case 1002:
                    FirstArrived();
                    break;

                case 1003:
                    FirstArrived();
                    break;

                case 1004:
                    onConnected(comi);
                    break;

                case 1005:
                    ("NaT SYMETRIC").p2pDEBUG();
                    break;

                case 1006:
                    ("1006 : " + comi.message).p2pDEBUG();
                    comi.messages = comi.message.Split(',');
                    onRequested(comi);
                    break;

                case 1007:
                    ("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT").p2pDEBUG();

                    if (Generate.ShowMeInfoWithMessageBox)
                        System.Windows.Forms.MessageBox.Show("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT");

                    if (Generate.ShowMeInfoWithConsole)
                        Console.WriteLine("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT");

                    break;

                case 1008:
                    ("1008 : " + comi.message).p2pDEBUG();
                    comi.messages = comi.message.Split(',');
                    onRequested(comi);
                    break;

                case 3000:
                    ("3000").p2pDEBUG();
                    break;

                case 3001:
                    ("3001").p2pDEBUG();
                    Recieved r = new Recieved();
                    r.data = comi.data;
                    r.id = comi.AgentID;
                    onRecieved(r);
                    break;

                case 3002:
                    ("3002").p2pDEBUG();
                    break;
            }
        }
        public Coming HaCo2(byte[] data, int size, Socket udp, EndPoint cep)
        {
            byte[] ET = new byte[4];
            byte[] DS = new byte[4];

            Array.Copy(data, 0, ET, 0, 4);
            Array.Copy(data, 4, DS, 0, 4);

            int messagesize = BitConverter.ToInt32(DS,0);

            byte[] message = new byte[messagesize];

            Array.Copy(data, 8, message,0, messagesize);

            int das = (size - (8 + messagesize));
            byte[] _data = new byte[das];

            Array.Copy(data, (8 + messagesize), _data,0, das);

            int EventType = BitConverter.ToInt32(ET, 0);
            string _message = Encoding.UTF8.GetString(message);

            Coming c = new Coming();
            c.EventType = EventType;
            c.message = _message;
            c.cep = cep;
            c._sock = udp;
            c.Address = ((IPEndPoint)cep).Address.ToString();
            c.port = ((IPEndPoint)cep).Port;
            c.data = _data;
            c.AgentID = _message;

            return c;
        }
Ejemplo n.º 21
0
        public Protocol(Coming comi)
        {
            switch (comi.EventType)
            {
            case 1001:
                FirstArrived();
                break;

            case 1002:
                FirstArrived();
                break;

            case 1003:
                FirstArrived();
                break;

            case 1004:
                onConnected(comi);
                break;

            case 1005:
                ("NaT SYMETRIC").p2pDEBUG();
                break;

            case 1006:
                ("1006 : " + comi.message).p2pDEBUG();
                comi.messages = comi.message.Split(',');
                onRequested(comi);
                break;

            case 1007:
                ("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT").p2pDEBUG();

                if (Generate.ShowMeInfoWithMessageBox)
                {
                    System.Windows.Forms.MessageBox.Show("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT");
                }

                if (Generate.ShowMeInfoWithConsole)
                {
                    Console.WriteLine("CLIENT DOES NOT EXISTS IN THE CURRENT CONTEXT");
                }

                break;

            case 1008:
                ("1008 : " + comi.message).p2pDEBUG();
                comi.messages = comi.message.Split(',');
                onRequested(comi);
                break;

            case 3000:
                ("3000").p2pDEBUG();
                break;

            case 3001:
                ("3001").p2pDEBUG();
                Recieved r = new Recieved();
                r.data = comi.data;
                r.id   = comi.AgentID;
                onRecieved(r);
                break;

            case 3002:
                ("3002").p2pDEBUG();
                break;
            }
        }
Ejemplo n.º 22
0
        private void p1000(Coming c)
        {
            Recording  recording = new Recording();
            clients    _clients  = recording.Record(ref c);
            DataHandle Handle    = new DataHandle();

            if (Agent.clients.ContainsKey(c.id))
            {
                #region XML && CLIENT UPLOADED

                XmlDocument xmld = new XmlDocument();
                try { xmld.Load(xmlPath); }
                catch { Thread.Sleep(50); xmld.Load(xmlPath); }
                foreach (XmlElement xmle in xmld.GetElementsByTagName("clients"))
                {
                    if (xmle["id"].InnerText.Equals(_clients.id, StringComparison.CurrentCultureIgnoreCase))
                    {
                        xmle["id"].InnerText         = _clients.id;
                        xmle["lep"].InnerText        = _clients.lep;
                        xmle["macAddress"].InnerText = _clients.macAddress;
                        xmle["licence"].InnerText    = _clients.licence;
                        xmle["Session"].InnerText    = (Convert.ToInt32(xmle["Session"].InnerText) + 1).ToString();
                        xmle["port"].InnerText       = _clients.port.ToString();
                        xmle["Address"].InnerText    = _clients.Address;
                        xmle["cep"].InnerText        = _clients.cep;
                    }
                }
                try { xmld.Save(xmlPath); }
                catch { Thread.Sleep(50); xmld.Save(xmlPath); }

                #endregion
                #region CLIENT CONNECTED AGAIN REPLACE PROPERTIES

                foreach (KeyValuePair <string, Coming> client in Agent.clients)
                {
                    if (client.Key.Equals(c.id, StringComparison.CurrentCultureIgnoreCase))
                    {
                        #region MAC ADDRESS DIFFERENT
                        if (!client.Value.macAddress.Equals("NOT"))
                        {
                            if (!client.Value.macAddress.Equals(c.macAddress))
                            {
                                byte[] data = Handle.HaSe(1001, "ID SAVED BEFORE FOR DIFFERENT CLIENT");
                                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                                return;
                            }
                        }
                        #endregion
                        #region CLIENT UPDATE
                        client.Value.lep        = c.lep;
                        client.Value._sock      = c._sock;
                        client.Value.Address    = c.Address;
                        client.Value.cep        = c.cep;
                        client.Value.EventType  = c.EventType;
                        client.Value.licence    = c.licence;
                        client.Value.macAddress = c.macAddress;
                        client.Value.message    = c.message;
                        client.Value.port       = c.port;
                        #endregion
                        byte[] d = Handle.HaSe(1002, "CLIENT ALREADY IN THE LIST");
                        c._sock.BeginSendTo(d, 0, d.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
                    }
                }

                #endregion
            }
            else
            {
                Agent.clients.Add(c.id, c);
                if (!File.Exists(xmlPath))
                {
                    #region WRITE DOC
                    XmlTextWriter writer = new XmlTextWriter(xmlPath, Encoding.UTF8);
                    writer.Formatting = Formatting.Indented;
                    writer.WriteComment("Saved Clients list");
                    writer.WriteStartElement("Clients");
                    writer.WriteEndElement();
                    writer.Close();
                    #endregion
                }
                #region XML SAVE
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Load(xmlPath);
                }

                XmlNode    client  = doc.DocumentElement;
                XmlElement element = doc.CreateElement("clients");

                XmlNode node1 = doc.CreateElement("id");
                node1.InnerText = _clients.id;
                element.AppendChild(node1);

                XmlNode node2 = doc.CreateElement("licence");
                node2.InnerText = _clients.licence;
                element.AppendChild(node2);

                XmlNode node3 = doc.CreateElement("macAddress");
                node3.InnerText = _clients.macAddress;
                element.AppendChild(node3);

                XmlNode node4 = doc.CreateElement("Address");
                node4.InnerText = _clients.Address;
                element.AppendChild(node4);

                XmlNode node5 = doc.CreateElement("port");
                node5.InnerText = _clients.port.ToString();
                element.AppendChild(node5);

                XmlNode node6 = doc.CreateElement("cep");
                node6.InnerText = _clients.cep;
                element.AppendChild(node6);

                XmlNode node7 = doc.CreateElement("lep");
                node7.InnerText = _clients.lep;
                element.AppendChild(node7);

                XmlNode node8 = doc.CreateElement("Session");
                node8.InnerText = "1";
                element.AppendChild(node8);

                XmlNode node9 = doc.CreateElement("message");
                node9.InnerText = _clients.message;
                element.AppendChild(node9);

                client.AppendChild(element);
                try
                {
                    doc.Save(xmlPath);
                }
                catch
                {
                    Thread.Sleep(50);
                    doc.Save(xmlPath);
                }
                #endregion
                byte[] data = Handle.HaSe(1003, "CLIENT RECORDED SUCCESFULY");
                c._sock.BeginSendTo(data, 0, data.Length, SocketFlags.None, c.cep, new AsyncCallback((async) => { }), c._sock);
            }
        }