Skip to content

Messages/Events received incomplete #168

Description

@Fragtality

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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions