Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: BJLU/EvCode
        private void NamingSocketForClient()         // function for communicating with client part
        {
            ListenerProperty.Bind(EndPointProperty); // initializing data about client part
            ShowMarker("socket -> Binded\n");
            ListenerProperty.Listen(10);             // opened port for connecting
            ShowMarker("socket -> listen\n");

            while (true)
            {
                ShowMarker($"waiting connecting through the port {EndPointProperty}\n");

                Socket handler = ListenerProperty.Accept(); // waiting to the client part
                if (handler != null)
                {
                    HandlerProperty = handler; // copy data to the current property
                    ShowMarker("connected -> client part\n");
                }
                else
                {
                    ShowMarker("connecting->error\n");
                }

                string data = null;                       // variable for content communications data between server and client part

                byte[] bytes    = new byte[1024];         // variable for got something data from client part
                int    bytesRec = handler.Receive(bytes); // performing got data
                ShowMarker("receiving data from client part\n");

                data += Encoding.UTF8.GetString(bytes, 0, bytesRec); // convert get data to the string type

                ShowMarker($"Receiving command: {data} \n\n");

                ValidationCommands(data); // send receiving data to the method for scanning to something commands
                //start entity

                string reply = $"query is performed -> length {data.Length.ToString()}"; // preparation data for sending to the client part

                byte[] msg = Encoding.UTF8.GetBytes(reply);                              // convert current data in bytes for sending
                handler.Send(msg);                                                       // sending current data to the client part
                ShowMarker("message -> sended\n");
            }
        }
Exemplo n.º 2
0
Arquivo: Form1.cs Projeto: BJLU/EvCode
        // i created it's two methods for saving laconic code size
        private string ReceivingData()                         // method for defined receiving query from client part
        {
            Socket handlerRefresh = ListenerProperty.Accept(); // defined accept client query

            if (handlerRefresh != null)                        // validation current variable
            {
                HandlerProperty = handlerRefresh;              // save data to the certain property
            }
            else
            {
                ShowMarker("handlerRefresh is null\n"); // out put message
            }

            string dataCom = null;                                  // variable for receiving data

            byte[] bytes    = new byte[1024];                       // variable for receiving data
            int    bytesRec = HandlerProperty.Receive(bytes);       // will got all data

            dataCom += Encoding.UTF8.GetString(bytes, 0, bytesRec); // got data in string type

            return(dataCom);                                        // transfer data
        }
Exemplo n.º 3
0
        internal void NamingSocket()                   // function for communicating with client part
        {
            ListenerProperty.Bind(IpEndPointProperty); // initializing data about client part
            ListenerProperty.Listen(10);               // opened port for connecting

            while (true)
            {
                Console.WriteLine($"waiting connecting through the port {IpEndPointProperty}");

                Socket handler = ListenerProperty.Accept(); // waiting to the client part
                if (handler == null)                        // if have something errors then
                {
                    Console.WriteLine("handler is null");
                }
                else
                {
                    HandlerProperty = handler; // copy data to the current property
                }

                string data = null;                                  // variable for content communications data between server and client part

                byte[] bytes    = new byte[1024];                    // variable for got something data from client part
                int    bytesRec = handler.Receive(bytes);            // performing got data

                data += Encoding.UTF8.GetString(bytes, 0, bytesRec); // convert get data to the string type

                Console.WriteLine($"Receiving command: {data} \n\n");

                ValidationCommands(data); // send receiving data to the method for scanning to something commands
                //start entity



                string reply = $"query is performed -> length {data.Length.ToString()}"; // preparation data for sending to the client part

                byte[] msg = Encoding.UTF8.GetBytes(reply);                              // convert current data in bytes for sending
                handler.Send(msg);                                                       // sending current data to the client part
            }
        }