Skip to content

WebSocket fragmented message problem #550

@aleks-f

Description

@aleks-f

From http://pocoproject.org/forum/viewtopic.php?f=12&t=6336

Postby DeVi » Thu Oct 02, 2014 10:11 am

Hi! I'm implementing a WebSocket client using poco-1.4.6p4. In case of a long message I fragment it into multiple binary frames. According to the example in the RFC (https://tools.ietf.org/html/rfc6455#section-5.4) the first frame must have the FRAME_OP_BINARY flag set. The second and other frames must have the FRAME_OP_CONT flag set. And the last frame must have FRAME_FLAG_FIN | FRAME_OP_CONT.
So the middle frames need to have FRAME_OP_CONT which is 0. But in Wireshark these frames also had the binary op code set, and the WebSocket server couldn't parse it. After a long investigation it turns out that WebSocketImpl::sendBytes in that case sets the flag to FRAME_BINARY.

CODE: SELECT ALL
int WebSocketImpl::sendBytes(const void* buffer, int length, int flags)
{
Poco::Buffer frame(length + MAX_HEADER_LENGTH);
Poco::MemoryOutputStream ostr(frame.begin(), frame.size());
Poco::BinaryWriter writer(ostr, Poco::BinaryWriter::NETWORK_BYTE_ORDER);

if (flags == 0) flags = WebSocket::FRAME_BINARY; // <-- HERE :)

I removed that line, recompiled POCO and now everything works as expected. I hope this helps, POCO is a really cool library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions