import java.io.OutputStreamWriter;
import java.net.Socket;
+import javax.net.ssl.SSLException;
+
import be.nikiroo.utils.Version;
import be.nikiroo.utils.serial.Exporter;
import be.nikiroo.utils.serial.Importer;
*/
public void connect() {
try {
- in = new BufferedReader(new InputStreamReader(s.getInputStream(),
- "UTF-8"));
+ in = new BufferedReader(
+ new InputStreamReader(s.getInputStream(), "UTF-8"));
try {
out = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
try {
if (server) {
+ String line = in.readLine();
+ if (line != null && line.startsWith("VERSION ")) {
+ // "VERSION client-version" (VERSION 1.0.0)
+ Version clientVersion = new Version(
+ line.substring("VERSION ".length()));
+ this.clientVersion = clientVersion;
+ Version v = negotiateVersion(clientVersion);
+ if (v == null) {
+ v = new Version();
+ }
+
+ sendString("VERSION " + v.toString());
+ }
+
action(clientVersion);
} else {
String v = sendString("VERSION " + version.toString());
}
} finally {
out.close();
+ out = null;
}
} finally {
in.close();
+ in = null;
}
} catch (Exception e) {
+ if (e instanceof SSLException) {
+ String ciphers = "";
+ for (String cipher : Server.getAnonCiphers()) {
+ if (!ciphers.isEmpty()) {
+ ciphers += ", ";
+ }
+ ciphers += cipher;
+ }
+
+ e = new SSLException(
+ "SSL error (available SSL ciphers: " + ciphers + ")",
+ e);
+ }
+
onError(e);
} finally {
try {
* @throws ClassNotFoundException
* if a class described in the serialised data cannot be found
*/
- protected Object sendObject(Object data) throws IOException,
- NoSuchFieldException, NoSuchMethodException, ClassNotFoundException {
+ protected Object sendObject(Object data)
+ throws IOException, NoSuchFieldException, NoSuchMethodException,
+ ClassNotFoundException {
synchronized (lock) {
- String rep = sendString(new Exporter().append(data).toString(true));
+ String rep = sendString(
+ new Exporter().append(data).toString(true, true));
if (rep != null) {
return new Importer().read(rep).getValue();
}
* @throws java.lang.NullPointerException
* if the counter part has no data to send
*/
- protected Object recObject() throws IOException, NoSuchFieldException,
- NoSuchMethodException, ClassNotFoundException,
- java.lang.NullPointerException {
+ protected Object recObject()
+ throws IOException, NoSuchFieldException, NoSuchMethodException,
+ ClassNotFoundException, java.lang.NullPointerException {
String str = recString();
if (str == null) {
throw new NullPointerException("No more data available");
contentToSend = false;
}
- String line = in.readLine();
- if (server && line != null && line.startsWith("VERSION ")) {
- // "VERSION client-version" (VERSION 1.0.0)
- Version clientVersion = new Version(
- line.substring("VERSION ".length()));
- this.clientVersion = clientVersion;
- Version v = negotiateVersion(clientVersion);
- if (v == null) {
- v = new Version();
- }
- sendString("VERSION " + v.toString());
-
- line = in.readLine();
- }
-
- return line;
+ return in.readLine();
}
return null;