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;
private OutputStreamWriter out;
private boolean contentToSend;
+ private long bytesReceived;
+ private long bytesSent;
+
/**
* Method that will be called when an action is performed on either the
* client or server this {@link ConnectAction} represent.
return version;
}
+ /**
+ * The total amount of bytes received.
+ *
+ * @return the amount of bytes received
+ */
+ public long getBytesReceived() {
+ return bytesReceived;
+ }
+
+ /**
+ * The total amount of bytes sent.
+ *
+ * @return the amount of bytes sent
+ */
+ public long getBytesSent() {
+ return bytesSent;
+ }
+
/**
* Actually start the process (this is synchronous).
*/
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 {
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();
}
synchronized (lock) {
out.write(line);
out.write("\n");
+ bytesSent += line.length() + 1;
if (server) {
out.flush();
}
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();
+ if (line != null) {
+ bytesReceived += line.length();
}
return line;