예제 #1
0
        private static void tryIt_RequestedDataReceived(DataRequestEventArgs args)
        {
            try
            {
                DateTime dtNow = DateTime.Now;
                requestCount++;
                lineCount += 1;

                if (lineCount % 10 == 0)
                {
                    lineCount = 0;
                    Console.Clear();
                }

                Console.WriteLine("------------------------------------------------");
                Console.WriteLine("[{0}. isteğe ait datalar:]", requestCount);

                for (int i = 0; i < args.RequestedData.Length; i++)
                {
                    Console.WriteLine("\tGelen data {0} : {1}", i + 1, args.RequestedData[i].ToString());
                }

                Console.WriteLine("Gelen komut          : {0}", Communicate.GetCommandName(args.RequestedData[1].ToString()));
                //Console.WriteLine("Anket tmp bilgi btn  : {0}", args.RequestedData[2].ToString());
                //Console.WriteLine("Anket tmp bilgi elt  : {0}", args.RequestedData[5].ToString());
                Console.WriteLine("Checksum değeri      : {0}", args.RequestedData[6]);
                Console.WriteLine("İstek zamanı         : {0}.{1}", dtNow, dtNow.Millisecond);
                Console.WriteLine("------------------------------------------------");

                Communicating.DecideCommandResponse(args.RequestedData);
            }
            catch (Exception hata)
            {
                Console.WriteLine("tryIt_RequestedDataReceived hata:" + hata.Message);
                OlayGunluk.Olay("tryIt_RequestedDataReceived hata:" + hata.Message);
            }
        }
예제 #2
0
        private void Listen()
        {
            int requestCount = 0;

            byte[]        bytesFrom      = new byte[10025];
            string        dataFromClient = null;
            NetworkStream networkStream  = null;

            string[] requestedData = new string[4];
            while ((clientSocket.Connected))
            {
                try
                {
                    DateTime dtNow = DateTime.Now; requestCount++;
                    networkStream = clientSocket.GetStream();
                    networkStream.Read(bytesFrom, 0, bytesFrom.Length); // (int)clientSocket.ReceiveBufferSize);
                    dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);

                    Console.WriteLine("------------------------------------------------");
                    Console.WriteLine("[{0}. isteğe ait datalar:]", requestCount);

                    int startIndex = 0;
                    int dataIndex  = 0;
                    int i          = 0;
                    while ((startIndex < dataFromClient.Length) && (dataIndex > -1))
                    {
                        dataIndex = dataFromClient.IndexOf("#", startIndex);

                        if (dataIndex == -1)
                        {
                            break;
                        }
                        requestedData[i] = dataFromClient.Substring(dataIndex + 1, 4).Replace("#", "");

                        startIndex += 4;

                        Console.WriteLine("\tGelen data {0} : {1}", i + 1, requestedData[i].ToString());
                        i++;
                    }


                    Console.WriteLine("Gelen komut          : {0}", Communicate.GetCommandName(requestedData[0]));
                    Console.WriteLine("İstek zamanı         : {0}.{1}", dtNow, dtNow.Millisecond);
                    Console.WriteLine("------------------------------------------------");

                    Communicating.DecideCommandResponse(requestedData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(" >> Bir hata meydana geldi {0}: ", ex.ToString());
                }
                finally
                {
                    if (networkStream != null)
                    {
                        networkStream.Flush();
                    }

                    if (clientSocket.Connected)
                    {
                        clientSocket.Close();
                    }
                }
            }
        }