Commit d510f0a3 authored by LIly's avatar LIly

update

parent 1be9caac
......@@ -14,6 +14,7 @@ import org.mpisws.helpers.Identifier;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
......@@ -132,17 +133,22 @@ public class SimulationClientBT {
return;
}
PrintWriter pw = new PrintWriter(os, true);
pw.println(serializedSecrets + serializedNonces + serializedPubKeys + "\r\n");
Log.d(TAG, "Lengths: " + serializedSecrets.length() + ", " + serializedNonces.length() + "," + serializedPubKeys.length());
Log.d(TAG, "Sent data over socket!");
DataOutputStream out = new DataOutputStream(os);
out.writeInt(serializedSecrets.length());
out.writeInt(serializedNonces.length());
out.writeInt(serializedPubKeys.length());
String toWrite = serializedSecrets + serializedNonces + serializedPubKeys;
out.writeChars(toWrite);
out.flush();
Log.d(TAG, "Lengths: " + toWrite.length() + ", "+ serializedSecrets.length() + ", " + serializedNonces.length() + "," + serializedPubKeys.length());
Log.d(TAG, "Sent data over socket! " + toWrite);
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line = in.readLine();
Log.d(TAG, "Got response: " + line);
in.close();
pw.close();
os.close();
sock.close();
} catch (IOException e) {
e.printStackTrace();
......@@ -155,7 +161,7 @@ public class SimulationClientBT {
private String serializeList(List<Identifier> list) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream so = new ObjectOutputStream(bo);
so.writeObject(mSharedSecrets);
so.writeObject(list);
so.flush();
Log.d(TAG, "Serialized string to " + bo.toString());
return bo.toString();
......
......@@ -20,6 +20,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.PrintStream;
......@@ -76,23 +77,28 @@ public class SimulationServerBT {
// If a connection was accepted
if (socket != null) {
DataInputStream in = new DataInputStream(socket.getInputStream());
byte[] messageByte = new byte[1000];
boolean end = false;
byte[] messageByte = new byte[3000];
String dataString = "";
int ssLen = in.readInt();
int nonceLen = in.readInt();
int pubKeyLen = in.readInt();
Log.d(TAG, ssLen + ", " + nonceLen + ", " + pubKeyLen);
while(true)
{
int bytesRead = in.read(messageByte);
dataString += new String(messageByte, 0, bytesRead);
Log.d(TAG, dataString);
if (dataString.contains(java.util.regex.Pattern.quote("\r\n"))) {
if (dataString.length() >= ssLen+nonceLen+pubKeyLen) {
break;
}
Log.d(TAG, "dataString length: " + dataString.length());
}
dataString.substring(0, dataString.indexOf(java.util.regex.Pattern.quote("\r\n")));
sharedSecrets = deserializeIDList(dataString.substring(0, dataString.length()/3));
nonces = deserializeIDList(dataString.substring(dataString.length()/3, 2*dataString.length()/3));
pubKeys = deserializeIDList(dataString.substring(2*dataString.length()/3));
Log.d(TAG, "dataString length: " + dataString.length());
sharedSecrets = deserializeIDList(dataString.substring(0, ssLen));
nonces = deserializeIDList(dataString.substring(ssLen, ssLen+nonceLen));
pubKeys = deserializeIDList(dataString.substring(ssLen+nonceLen, ssLen+nonceLen+pubKeyLen));
if (sharedSecrets == null || nonces == null || pubKeys == null) {
return;
}
......@@ -117,6 +123,7 @@ public class SimulationServerBT {
ByteArrayInputStream bi = new ByteArrayInputStream(b);
ObjectInputStream si = new ObjectInputStream(bi);
List<Identifier> obj = (List<Identifier>) si.readObject();
Log.d(TAG, "Deserialized! " + obj.size());
return obj;
}
private void processData() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment