コード例 #1
0
ファイル: ServerConnect.cs プロジェクト: comp6720/ToyDBServer
        /**
         * Receive query from the client.
         * Create a byte object to store data coming from client.
         * The data coming from the client will be in bytes.
         * The data in bytes is then be converted back to a string.
         *
         * @return void
         */
        public void ReceiveQuery()
        {
            try
            {
                byte[] queryMessage = new Byte[1024];
                int    byteRecv     = ClientSocket.Receive(queryMessage);
                string data         = Encoding.ASCII.GetString(queryMessage, 0, byteRecv);

                //Output message from client in the console
                Console.WriteLine("Query received -> {0} ", data);

                //Parse the query
                SQLParser.SQLRouteCommand(data);
            }

            // Management of Socket's Exceptions
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }

            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }

            catch (ObjectDisposedException ode)
            {
                Console.WriteLine("ObjectDisposedException : {0}", ode.ToString());
            }

            catch (System.Security.SecurityException ssse)
            {
                Console.WriteLine("SecurityException : {0}", ssse.ToString());
            }

            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
            }
        }