Description
I'm trying to integrate JavaOSC into an Android (Kotlin) app. I need to use TCP, so I downloaded the current version of the source code but rolled back first change in 2cbbc43 so it would run on Android. Here's my code to connect to a server and send some data:
val remoteSocketAddress = InetSocketAddress("10.0.1.24", 24601)
val localSocketAddress = InetSocketAddress(this.myAddress, 24601)
val client: OSCPortOut?
try {
client = OSCPortOutBuilder().setLocalSocketAddress(localSocketAddress).setRemoteSocketAddress(remoteSocketAddress).setNetworkProtocol(NetworkProtocol.TCP).build()
} catch (e: Exception) {
Log.d("serverConnect", "error creating client")
return
}
val data = arrayListOf<Any>("a", "b", "c")
App.instance.runInBackground({ // sending will throw an exception if run on the main thread
val message = OSCMessage("/my/app/setup", data)
try {
client.send(message)
} catch (e: Exception) {
Log.d("serverConnectContinue", "error sending to server")
}
})
For testing, I'm sending to the OSCSmith app on my Mac. That shows the Android app connecting and then disconnecting in the same second, but it doesn't show any data received. However, I can add breakpoints to the source code and see that it's getting all the way to ByteArrayListBytesReceiver.writeTo(), and the data there is correct. I don't know why the OutputStream from that point isn't delivering the data to the server.
If I change the network protocol to UDP and leave all the other code the same, the data is sent as expected. (OSCSmith can receive on TCP or UDP and with TCP can receive SLIP or PLH format. I have it set to PLH because it sounds like JavaOSC doesn't support SLIP yet.)
I think the connection and immediate disconnection is expected, because a comment in TCPTransport.send() says, "Closing the output stream is necessary...." I can't find what part of the code triggers the disconnection, but when I add a breakpoint at the end of ByteArrayListBytesReceiver.writeTo(), I can see that the disconnect doesn't happen until after all the data is written.
I'm not getting any errors in the Android Studio console. It's like the data is just disappearing. Can anyone, perhaps @daveyarwood, who added TCP compatibility, give any insight on this?