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

Messages/Events received incomplete #168

Open
Fragtality opened this issue Feb 5, 2021 · 0 comments
Open

Messages/Events received incomplete #168

Fragtality opened this issue Feb 5, 2021 · 0 comments

Comments

@Fragtality
Copy link

Describe the bug
Messages/Events send to StreamDeckLib are not received completely (split in half), therefor json-Parsing fails and therefor the Event is missed. The resulting jsonString suddenly ends, the second half is received with the next ReceiveAsync.

To Reproduce
Difficult - modified & self compiled copy of StreamDeckLib. Roughly: compiled as .NET Framework, ConnectionManager.Run modified to repeatedly call my Code. On top of that, it only happens in some combination / quantity of my plugin-buttons.

Expected behavior
Receiving the whole Message / Event ;)

Proposed Fix
public async Task GetMessageAsString(CancellationToken token)
{
byte[] buffer = new byte[65536];
ArraySegment segment = new ArraySegment(buffer, 0, buffer.Length); ;
WebSocketReceiveResult result = new WebSocketReceiveResult(0, WebSocketMessageType.Text, false);
int totalCount = 0;
while (!result.EndOfMessage)
{
result = await _Socket.ReceiveAsync(segment, token);
totalCount += result.Count;
segment = new ArraySegment(buffer, totalCount, buffer.Length - totalCount);
}
string jsonString = Encoding.UTF8.GetString(buffer);

return jsonString;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant