Beispiel #1
0
        static void ConnectFunc(object client_obj)
        {
            string[] split;
            byte[]   msg;
            DBMySQL  db = new DBMySQL();

            Byte[] bytes = new Byte[256];
            String data  = null;

            TcpClient client = client_obj as TcpClient;

            data = null;

            NetworkStream stream = client.GetStream();

            //Information info = new Information();

            int i;

            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
            {
                data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

                split = data.Split(new Char[] { ' ' });

                switch (split[0])
                {
                case "HELLO":
                    msg = System.Text.Encoding.ASCII.GetBytes(db.GetAutomatsNumbers().ToString());
                    break;

                //TRANSACTION_TYPE
                //TRANSACTION_TIME
                case "TRANSACTION_TYPE":
                    string s = db.GetTransactionType(split[1], 1).ToString() + " "
                               + db.GetTransactionType(split[1], 2).ToString() + " "
                               + db.GetTransactionType(split[1], 3).ToString();
                    msg = System.Text.Encoding.ASCII.GetBytes("ANSWER_TYPE " + s);
                    break;

                case "TRANSACTION_TIME":
                    string s1 = "";
                    for (int iter = 0; iter < 24; iter++)
                    {
                        s1 += " " + db.GetTransactionTime(split[1], iter.ToString());
                    }
                    msg = System.Text.Encoding.ASCII.GetBytes("ANSWER_TIME" + s1);
                    break;

                default:
                    msg = System.Text.Encoding.ASCII.GetBytes("Unknown Command");
                    break;
                }

                stream.Write(msg, 0, msg.Length);
            }
        }
Beispiel #2
0
        static void ConnectFunc(object client_obj)
        {

            string[] split;
            byte[] msg;
            DBMySQL db = new DBMySQL();
            Byte[] bytes = new Byte[256];
            String data = null;

            TcpClient client = client_obj as TcpClient;

            data = null;

            NetworkStream stream = client.GetStream();

            //Information info = new Information();

            int i;
            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
            {
                data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

                split = data.Split(new Char[] { ' ' });

                switch (split[0])
                {
                    case "HELLO":
                        msg = System.Text.Encoding.ASCII.GetBytes(db.GetAutomatsNumbers().ToString());
                        break;
                    //TRANSACTION_TYPE
                    //TRANSACTION_TIME
                    case "TRANSACTION_TYPE":
                        string s = db.GetTransactionType(split[1], 1).ToString() + " "
                            + db.GetTransactionType(split[1], 2).ToString() + " "
                            + db.GetTransactionType(split[1], 3).ToString();
                        msg = System.Text.Encoding.ASCII.GetBytes("ANSWER_TYPE " + s);
                        break;
                        
                    case "TRANSACTION_TIME":
                        string s1 = "";
                        for (int iter = 0; iter < 24; iter++ )
                        {
                            s1 += " " + db.GetTransactionTime(split[1], iter.ToString());
                        }
                        msg = System.Text.Encoding.ASCII.GetBytes("ANSWER_TIME" + s1);
                        break;                   
                        
                    default:
                        msg = System.Text.Encoding.ASCII.GetBytes("Unknown Command");
                        break;
                }

                stream.Write(msg, 0, msg.Length);
            }
        }