Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream payload not being sent if associated streams have no data yet #3176

Open
fabrizioiacobucci opened this issue Jan 24, 2025 · 1 comment
Labels
needs-triage Issue still needs to be assigned, labeled and deduplicated type: bug Something is broken or not working as intended

Comments

@fabrizioiacobucci
Copy link

Project

Nearby Connections

Language

C++

OS Platform

Other

What happened?

[RUNNING THIS ON ANDROID]

I'm using the compiled SDK to create an Expo module to use in our future app.
So actually I'm not really aware of what happens under the hood in this codebase and I apologize in advance if this is not the right place where to post this.

I'm able to let everything working as expected (advertising, discovering, connections, etc..).
However, when trying to send a Stream payload, even if it is correctly sent (I can see a log printed in the sendPayload Task onSuccess listener), it is not received from the target endpoint.

Investigating the issue, I found out the stream payload was not sent because the associated stream had no data yet to read.
How I was generating the payload:

val pipedOutputStream = PipedOutputStream()
val pipedInputStream = PipedInputStream(pipedOutputStream, data.size)
val payload = Payload.fromStream(pipedInputStream)

and then just sending it out with: connectionsClient.sendPayload(endpointIdsStrings, payload)

it was correctly sent but not received.

As soon as I write even a single byte to the outputStream before sending the Payload, it is then correctly received on the other hand and I can continue writing my data.

As I see, e.g., Piped streams can be created and connected and just wait for new data. I don't understand why a stream payload can't be sent and waiting for it.

Thanks!

What did you expect to happen?

I would expect that I can send a Stream Payload even if no data has been written yet.

How can we reproduce it (as minimally and precisely as possible)?

  1. Having 2 devices already connected (any strategy is ok)
  2. Create a PipedInputStream and a PipedOutputStream, connect them together
  3. Generate a Stream payload with the previously created input stream
  4. send the stream payload to the other device
  5. the other device will never receive it

How often does this bug happen?

Every time

Standalone code to reproduce the issue

import com.google.android.gms.nearby.Nearby
import com.google.android.gms.nearby.connection.Payload
import java.io.PipedInputStream
import java.io.PipedOutputStream

val _connectionsClient = Nearby.getConnectionsClient(_safeCurrentActivity)
val pipedOutputStream = PipedOutputStream()
val pipedInputStream = PipedInputStream(pipedOutputStream, 1024)
val payload = Payload.fromStream(pipedInputStream)
_connectionsClient.sendPayload(<id of  the target device>, payload)

Relevant log output

Anything else we need to know?

No response

@fabrizioiacobucci fabrizioiacobucci added needs-triage Issue still needs to be assigned, labeled and deduplicated type: bug Something is broken or not working as intended labels Jan 24, 2025
@bourdakos1
Copy link
Collaborator

I believe this is the intended behavior. Under the hood a stream payload gets turned into a series of byte payloads, so if there is nothing in the stream, no byte payloads get sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue still needs to be assigned, labeled and deduplicated type: bug Something is broken or not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants