niv / websocket.nim

websockets for nim
http://niv.github.io/websocket.nim/docs/0.1.1/websocket.html
Other
101 stars 25 forks source link

Sending data over 0x7fff bytes breaks. #18

Closed treeform closed 6 years ago

treeform commented 6 years ago

The problem is on https://github.com/niv/websocket.nim/blob/master/websocket/shared.nim#L57 ret.write(int64 f.data.len.int32.htonl) and 0x7fff

Is not correct way to do, it should be some thing like:

if f.data.len > 125 and f.data.len <= 0xffff:
    ret.write(uint16 f.data.len.uint16.htons)
elif f.data.len > 0xffff:
    var len = f.data.len
    ret.write char((len shr 56) and 255)
    ret.write char((len shr 48) and 255)
    ret.write char((len shr 40) and 255)
    ret.write char((len shr 32) and 255)
    ret.write char((len shr 24) and 255)
    ret.write char((len shr 16) and 255)
    ret.write char((len shr 8) and 255)
    ret.write char(len and 255)
metagn commented 6 years ago

Perhaps you could submit a pull request?