Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you connect roblox to a websocket?

Asked by 7 years ago

Would it be possible to connect to a websocket with roblox? I don't need directly, like say GetAsync my website with the javascript websocket, but it doesn't keep the connection. If you wanna know what I'm using this for it is a "Roblox hosted discord bot" I've already got a working version and it does what I need it to, but a way to do some type of connection with a websocket or someting would boost this a lot.

Here is the "websocket" connection I attempted

local http = game:GetService("HttpService")
spawn(function()
while wait(3) do
http:GetAsync("private_url")
end
end)

The reason that failed is because of two reasons 1. For the bot to stay online/etc it'd have to be constant connection 2. I have to wait 1-2 seconds until I can connect to the websocket

0
You only have access to the protocols http and https you cannot use any other protocols User#5423 17 — 7y
0
The ROBLOX HTTPService cannot have a keep alive(maybe) but once it completes it's request, it is terminated immediately. Why can't you just run a server on your computer, portforward them? ISP problems? server problems? I might able to fix 'em httpOmqCxpcake 70 — 7y
0
I don't have the tools to do so, this isn't my laptop since mine broke so I don't wanna download stuff, but this laptop is also too slow for any of the normal bot creation tools (vs,node,etc) fireboltofdeathalt 118 — 7y

1 answer

Log in to vote
0
Answered by 5 years ago

try this

local http = game:GetService("HttpService")

spawn(function()
    local maxReqPerSec = 3
    while this.alive == true do
        local tm = tick()
        http:GetAsync("your_url")
        local dur = (tick() - tm)
        local waitTime = math.max(0,((1/maxReqPerSec) - dur))
        wait(waitTime)
    end
end)
Ad

Answer this question