diff --git a/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java b/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java index cbbfdd5..5132691 100644 --- a/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java +++ b/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java @@ -51,19 +51,18 @@ public void doOnBackground() { //TODO Use buffered streams. Log.v(Salut.TAG, "Sending client registration data to server..."); String serializedClient = LoganSquare.serialize(salutInstance.thisDevice); - BufferedOutputStream bufferedOut = new BufferedOutputStream(registrationSocket.getOutputStream()); - DataOutputStream toClient = new DataOutputStream(bufferedOut); + DataOutputStream toClient = new DataOutputStream(registrationSocket.getOutputStream()); toClient.writeUTF(serializedClient); toClient.flush(); - Log.v(Salut.TAG, "Receiving server registration data..."); - BufferedInputStream bufferedInput = new BufferedInputStream(registrationSocket.getInputStream()); - DataInputStream fromServer = new DataInputStream(bufferedInput); + DataInputStream fromServer = new DataInputStream(registrationSocket.getInputStream()); if(!salutInstance.thisDevice.isRegistered) { + Log.v(Salut.TAG, "Receiving server registration data..."); String serializedServer = fromServer.readUTF(); SalutDevice serverDevice = LoganSquare.parse(serializedServer, SalutDevice.class); + serverDevice.serviceAddress = registrationSocket.getInetAddress().toString().replace("/", ""); salutInstance.registeredHost = serverDevice; diff --git a/src/main/java/com/peak/salut/BackgroundDataJob.java b/src/main/java/com/peak/salut/BackgroundDataJob.java index 004087b..ddd39de 100644 --- a/src/main/java/com/peak/salut/BackgroundDataJob.java +++ b/src/main/java/com/peak/salut/BackgroundDataJob.java @@ -4,6 +4,7 @@ import com.arasthel.asyncjob.AsyncJob; import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.DataInputStream; import java.net.Socket; @@ -27,8 +28,8 @@ public void doOnBackground() { { //If this code is reached, a client has connected and transferred data. Log.v(Salut.TAG, "A device is sending data..."); - BufferedInputStream bufferedRead = new BufferedInputStream(clientSocket.getInputStream()); - DataInputStream dataStreamFromOtherDevice = new DataInputStream(bufferedRead); + + DataInputStream dataStreamFromOtherDevice = new DataInputStream(clientSocket.getInputStream()); data = dataStreamFromOtherDevice.readUTF(); dataStreamFromOtherDevice.close(); diff --git a/src/main/java/com/peak/salut/BackgroundDataSendJob.java b/src/main/java/com/peak/salut/BackgroundDataSendJob.java index db67b8c..5ff264b 100644 --- a/src/main/java/com/peak/salut/BackgroundDataSendJob.java +++ b/src/main/java/com/peak/salut/BackgroundDataSendJob.java @@ -43,8 +43,7 @@ public void doOnBackground() { //If this code is reached, a client has connected and transferred data. Log.d(Salut.TAG, "Connected, transferring data..."); - BufferedOutputStream bufferedOut = new BufferedOutputStream(dataSocket.getOutputStream()); - DataOutputStream dataStreamToOtherDevice = new DataOutputStream(bufferedOut); + DataOutputStream dataStreamToOtherDevice = new DataOutputStream(dataSocket.getOutputStream()); String dataToSend = LoganSquare.serialize(data); dataStreamToOtherDevice.writeUTF(dataToSend); dataStreamToOtherDevice.flush(); diff --git a/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java b/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java index d4e8607..8415182 100644 --- a/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java +++ b/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java @@ -29,15 +29,16 @@ public void doOnBackground() { Log.d(Salut.TAG, "A device has connected to the server, transferring data..."); Log.v(Salut.TAG, "Receiving client registration data..."); - BufferedInputStream bufferInput = new BufferedInputStream(clientSocket.getInputStream()); - DataInputStream fromClient = new DataInputStream(bufferInput); + DataInputStream fromClient = new DataInputStream(clientSocket.getInputStream()); String serializedClient = fromClient.readUTF(); + System.out.println(serializedClient); + + SalutDevice clientDevice = LoganSquare.parse(serializedClient, SalutDevice.class); clientDevice.serviceAddress = clientSocket.getInetAddress().toString().replace("/", ""); - BufferedOutputStream bufferedOut = new BufferedOutputStream(clientSocket.getOutputStream()); - DataOutputStream toClient = new DataOutputStream(bufferedOut); + DataOutputStream toClient = new DataOutputStream(clientSocket.getOutputStream()); if (!clientDevice.isRegistered) { diff --git a/src/main/java/com/peak/salut/SalutBroadcastReciever.java b/src/main/java/com/peak/salut/SalutBroadcastReciever.java index 9cca4d4..2a9e7ee 100644 --- a/src/main/java/com/peak/salut/SalutBroadcastReciever.java +++ b/src/main/java/com/peak/salut/SalutBroadcastReciever.java @@ -46,7 +46,6 @@ public void onReceive(Context context, Intent intent) { NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); if (networkInfo.isConnected() && networkInfo.getTypeName().equals("WIFI_P2P")) { - salutInstance.isConnectedToAnotherDevice = true; manager.requestConnectionInfo(channel, salutInstance);