FredyH / GWSockets

WebSockets for GLua
MIT License
87 stars 7 forks source link

Socket:write() appears to truncate data after 4kb #22

Closed Fatal93 closed 4 years ago

Fatal93 commented 4 years ago

I'm using GWSockets to send a JSON Payload to a Websocket server, however during my testing I've come across an issue, seemingly seems to happen at random, I'm not able to find any specific pattern, however the longer the map has been on, the more likely it seems to happen.

Data after 4000 bytes seems to be just replaced with NULL. See my screenshots below: nulldata

This is from the Websocket when the JSON conversion fails.

I've tried the following:

I've ruled out that it may be something with the Gmod JSON data or my websocket server so it appears to be an issue with this module.

I'm using the latest version, which at the time of writing is: 1.1.3

If there's any more information you need, let me know.

FredyH commented 4 years ago

I just ran the following:

require("gwsockets")

local socket = GWSockets.createWebSocket("wss://echo.websocket.org")

function socket:onMessage(txt)
    for i = 1, #txt do
        if (txt[i] != "5") then
            print("Fail")
        end
    end
    print(txt[8000])
end

function socket:onError(txt)
    print("Error: ", txt)
end

function socket:onConnected()
    socket:write(string.rep("5", 8000))
end

socket:open()

And it worked as expected. Could I see your code?

FredyH commented 4 years ago

I think I found the problem and it's actually quite a severe bug. I pushed the changes and will probably release a new version today.

FredyH commented 4 years ago

I just released 1.2.0, would be great if you could test and see if it is fixed.

Fatal93 commented 4 years ago

Great thanks, I'll give it a test this afternoon once I'm back from work.

Fatal93 commented 4 years ago

I've just done some testing, and can confirm the issue is now fixed. Thank you 👍