Hey everyone,
I am trying to make a plugin that gets JSON data from a port. How can I do this?
Thanks in advance.
Hey everyone,
I am trying to make a plugin that gets JSON data from a port. How can I do this?
Thanks in advance.
I’ve been spending a lot of time searching through the documentation and I can not find anything. Has anyone ever had to do anything like listening to a port?
Can you explain what you mean? I don’t think you can listen for incoming data to a Roblox game, you would have to set up a server at a port and Request data from it.
I mean in a way kind of like how Rojo works. Rojo connects to Roblox Studio by entering a port. I have an application that currently has a server set up at a port, but I don’t know how to get a Roblox plugin to get JSON data from that port.
Just do RequestAsync
to 127.0.0.1:YOURPORTHERE (or a specific IP if it’s not hosted locally). You can view Rojo’s source specifically here: https://github.com/Roblox/rojo/tree/master/plugin. Relevant bit:
https://github.com/Roblox/rojo/blob/master/plugin/src/Components/App.lua#LC113
Do I put it in the URL?
{
Url = "127.0.0.1:"..port, -- This website helps debug HTTP requests
Method = "POST",
Headers = {
["Content-Type"] = "application/json" -- When sending JSON, set this!
},
Body = HttpService:JSONEncode({hello = "world"})
}
)```
Yeah, the port is just a part of the URL.
It tells me:
HTTP Services are not allowed to access ROBLOX services.
local function request()
local response = HttpService:RequestAsync(
{
Url = "127.0.0.1:24981", -- This website helps debug HTTP requests
}
)
-- Inspect the response table
-- if response.Success then
-- print("Status code:", response.StatusCode, response.StatusMessage)
-- print("Response body:\n", response.Body)
-- else
-- print("The request failed:", response.StatusCode, response.StatusMessage)
-- end
end
-- Remember to wrap the function in a 'pcall' to prevent the script from breaking if the request fails
while wait() do
local success, message = pcall(request)
if not success then
print("Http Request failed:", message)
end
end
That is my current code.
If you’re using it in a live game server, you have to reference your server using the actual IP. 127.0.0.1 is just the localhost.
It’s a plugin running off Roblox studio, so isn’t that local?
Yeah, that should be working fine. Odd. I guess Roblox doesn’t allow 127.0.0.1 at all, so you’d have to do your actual IP.
Try putting a protocol before 127.0.0.1, so http://
or https://
.
local function request()
local response = HttpService:GetAsync("https://127.0.0.1:24981")
end
Now it just says “ConnectFail”
To specify, I am attempting to connect to the program Quixel Bridge. When I open its logs, it says its sending to “127.0.0.1:24981”, but my Roblox plugin is not connecting.
That means it can’t find whatever is hosted at that port. Could you have typed the port number wrong, or could it be expecting a different HTTP Method?
I tried all 3 HTTP methods and copied the port directly from Quixel Bridge.
Actually, now that I am trying it… Just simply typing into my browser 127.0.0.1 refuses to connect. It seems this isn’t a issue with my Roblox code.