Example #1
0
        public static void StartRead()
        {
            //a pdfek várásának elindítása

            while (true)
            {
                //a szerverre való csatlakozás inditása
                DocsShowClient.Connect();

                //a pdfek olvasássa
                DocsShowClient.ReadMSG();
            }
        }
Example #2
0
        //egy üzenet kiolvasása és utána válaszolja azt ami az üzenetben van
        public static string ReadMSG()
        {
            string readedMSG = "/non";

            byte[] buffer = new byte[DocsShowClient.ClientTCP.ReceiveBufferSize];

            DocsShowClient.ClientStream.Read(buffer, 0, buffer.Length);

            readedMSG = Encoding.UTF8.GetString(buffer).TrimEnd('\0');

            if (readedMSG == "")
            {
                throw new IOException("A kapcsolat megszakadt a szerverrel ismeretlen hiba által");
            }

            if (readedMSG.Contains("/check"))
            {
                readedMSG = readedMSG.Replace("/check", "");

                SendingOperations.WriteMSG("/ok");
            }

            if (readedMSG.StartsWith("/"))
            {
                string[] datas = readedMSG.Split(' ');

                try
                {
                    CommandManager.Manager(datas[0], GetRealParams.GetRealParamsFromRawParams(datas));
                }
                catch (ApplicationException ex)
                {
                    DocsShowClient.Disconnect();

                    EndMethodsLibrary.EndMethods.End(ex.Message);
                }


                return(readedMSG);
            }
            else
            {
                return(readedMSG);
            }
        }
Example #3
0
        //a csatlakozás elvégézése
        public static void CheckConnection()
        {
            string msg = ReadingMethods.ReadMSG();

            if (msg == "/okdatas")
            {
                //sikeres kapcsolodás
                Console.WriteLine($"{DateTime.Now.ToString()}:Sikeres kapcsolodás a {Datas.CommandServerIP}:{Datas.CommandPort} doksi kiszolgáló szerverhez");
                SendingOperations.WriteMSG("/connected");
            }
            else if (msg == "/inUse")
            {
                //a szerverre már felcsatlakoztak ezzel az IPvel
                throw new SocketException(10048);
            }
            else
            {
                //a válasz nem volt értelmezhető
                DocsShowClient.Disconnect();
                throw new ApplicationException("A szerver visszautasította az adatok kezelését");
            }
        }