1

Hey Guys i am starting an EPP client and it only returns the greeting from the server, even when i try send my login command.

here is my code, what is wrong with it?

     using (var _tcpClient = new TcpClient(_endpoint.Host, _endpoint.Port))
     {

            using (var sslStream = new SslStream(_tcpClient.GetStream(), false, ValidateServerCertificate))
            {
                sslStream.AuthenticateAsClient(_endpoint.Host);

                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(requestData);
                xdoc.Save("C:/request.xml");
                string data = xdoc.InnerXml;
                byte[] bytedata = Encoding.UTF8.GetBytes(data);
                //Get the request stream.
                sslStream.Write(bytedata, 0, bytedata.Length);
                // Write the data to the request stream.


                sslStream.Flush();

                var response = ReadMessage(sslStream);
                XResponse = XDocument.Parse(response);

                XResponse.Save("C:/response.xml");
            }

        }
        return XResponse;
    }

    private string ReadMessage(SslStream sslStream)
    {
        // The first four bytes will be the the content length as a network order (big-endian) 32-bit number.  
        var lengthBytes = new byte[4];
        sslStream.Read(lengthBytes, 0, 4);
        Array.Reverse(lengthBytes);

        var length = BitConverter.ToInt32(lengthBytes, 0) - 4;

        // Create a byte array of the correct size for the response.  
        var messageBytes = new byte[length];

        var returned = 0;

        while (returned != length)
        {
            returned += sslStream.Read(messageBytes, 0, length);
        }

        return Encoding.UTF8.GetString(messageBytes);
    }  

Even if i do not write anything with the ssl stream it still returns the greeting.

if you guys could point me in the right direction it would be greatly appreciated.

CKG
  • 13
  • 3

2 Answers2

3

Each time you send any command or open a connection, you must read and flush the response. I fell into this trap when developing my EPP client.

Connect. Read response (you get the greeting) Send Login command. Read response (you get the login response) Send Command. Read Response. Send Disconnect. Read Response.

I imagine you're connecting, then sending a login command and wondering why the response you just got was the greeting. You missed a step. :)

IntoNET
  • 456
  • 2
  • 14
  • THIS!!! i eventually did get it working but forgot to update the question so thank you :) – CKG Jul 15 '16 at 10:37
  • I currently have the same problem, what do you mean by "read the response" ? I used sockets to return the response of the server, and I even went further and send a hello request after every command, but no matter what I do, domain:check and domain:info always return empty strings. – SmootQ Apr 01 '19 at 13:35
  • Hello, As per @IntoNet answer i did try to get request then send login but on login i am not geting response. Maybe i am doing something wrong. Can someone share code example? – Kosta Stojcev May 21 '22 at 05:55
1

Upon connection the server will typically reply with a greeting.

Read the greeting response upon connection. Then you can send commands and receive responses as normal.

davidf
  • 937
  • 6
  • 5