How to get state of extensions

I am trying to get state of current extension like busy,in Use etc. i have used below code to get response from asterisk server:
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(m_ippbx), 5038);

        clientSocket.Send(Encoding.ASCII.GetBytes("Action: Login\r\nUsername: " + m_user + "\r\nSecret: " + m_pass + "\r\nActionID: 1\r\n\r\n"));
        int bytesRead = 0;
        int bytesRead1 = 0;
            byte[] buffer = new byte[1024];
            bytesRead = clientSocket.Receive(buffer);

            response = Encoding.ASCII.GetString(buffer, 0, bytesRead);

            if (Regex.Match(response, "Message: Authentication accepted", RegexOptions.IgnoreCase).Success)
                    clientSocket.Send(Encoding.ASCII.GetBytes("Action: ExtensionState\r\nContext: from-internal\r\nExten: " + number + "\r\nActionID: 1\r\n\r\n"));
                    byte[] buffer1 = new byte[1024];
                    bytesRead1 = clientSocket.Receive(buffer1);
                    response1 = Encoding.ASCII.GetString(buffer1, 0, bytesRead1);
                    return response1;

while (bytesRead1 != 0);


when i am running this code sometimes returns response like:
Event: FullyBooted
Privilege: system,all
Status: Fully Booted
Response: Success

can any one help me why i am not able to get correct response from extension State event.

thanks in advance