问题
tI'm implementing a client in java that comunicates to an EPP server via TCP and SSL.
I nead to send some xml-s to the server via SSL an read some xml responses. I dont have a client certificate and I dont nead one. I just nead to be able to send requests to that server and read responses. Im quite new to this topic.
My code is this :
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("server.epp.si", 65000);
DataOutputStream outToServerSSL = new DataOutputStream(sslsocket.getOutputStream());
BufferedReader inFromServerSSL = new BufferedReader(new InputStreamReader(sslsocket.getInputStream()));
outToServerSSL.write(somXML.getBytes());
inFromServerSSL.readLine();
It doesn't depens what string I put in the xml I get always the same greating xml response back.
Now I'm wondering if even the SSL hanshake went OK. How is possible to check it the connection is successfuly established and that the reciever is ready to receive data. So that I exlude the connection problem itself.
回答1:
Standard EPP is defined to always send the greeting on connection to the server, so in your code above you are writing your command to the server but the input buffer will already have the greeting on, so this is what you would get back when reading the response.
The correct flow is as follows
- Connect to EPP Server via SSLSocket
- Read the greeting from the input stream
- Send the login command
- Read the login response
- Send your EPP command
- Read the Response to your commands
- Repeat steps 5&6 until you have done everything necessary
- Send the logout command
- Read the logout response
- Close the socket
回答2:
You can debug the communication when running your project with
java -Djavax.net.debug=all
.
You can see the whole handshake, it should end with
*** Finished
verify_data:...
****
and then some plain and encrypted data.
来源:https://stackoverflow.com/questions/22013287/ssl-socket-communicatoin-to-an-epp-server