[ARCHIVED] FastNet2 - a fast, efficient & lightweight network library

FastNet2 Documentation is now fixed.

2 Likes

Might not be an issue, but it could potentially annoy some of the fastnet users that it will be using the unreliable by default.
Thanks for the update though! :+1:

how do i connect a fastnet connection thingy to send over 144p worth of rgbvalues of my screen every millisecond from a serverscript to a localscript, do I use its 'fastnet.Connect(ā€˜colorsendā€™) or smth else.
heres the end of my localscript:local rgbstuff = FastNet2.Connect(ā€˜colorsendā€™)
rgbstuff:Connect(function(updatedRGBValues)

	updatePixels(updatedRGBValues)

end)

also i just upgraded from bridgenet2 since i couldnā€™t get any help there, since this post looks more active i will start using fastnet.

if you want, i can pass over abit of my server script and localscript, heres server (also im using the remote event functionality in the module not remote function, also in the server side it sends 3 tables i assume in the event, does your module support tables? ;

local rgbvalues = FastNet2.new('colorsend');


wrap(function()
	while true do
		local RGBValues
		repeat
			RGBValues = RequestRGBValues(_G.URL)
			
		until RGBValues
		if _G.framerate == 60 or _G.framerate == 20 then
	       rgbvalues:Fire(RGBValues)
		
			print('sent')
		else
			
			rgbvalues:Fire(RGBValues)
	
		end
	end
end)()

heres local:

local function updatePixels(updatedRGBValues)
	local rgb = table.create(3)
	for index = 1, totalPixels do
		local updatedRGBValue = updatedRGBValues[index]
		if updatedRGBValue then
			rgb[1], rgb[2], rgb[3] = updatedRGBValue[1], updatedRGBValue[2], updatedRGBValue[3]
			local r, g, b = rgb[1], rgb[2], rgb[3]
			local colorKey = bit_bor(bit_lshift(r, 16), bit_lshift(g, 8), b)
			if not colorCache[colorKey] then
				colorCache[colorKey] = Color3_fromRGB(r, g, b)
			end
			pixels[index].BackgroundColor3 = colorCache[colorKey]
		end
	end
end

local ren = RunService.RenderStepped
ren:Connect(function()
	if currentBatchStart <= totalPixels then
		createNextBatch()
	end
end)

local rgbstuff = FastNet2.Connect('colorsend')
rgbstuff:Connect(function(updatedRGBValues)

		updatePixels(updatedRGBValues)
	
end)

oh nvm i figured it out i used listen heres my end part:

local rgbstuff = FastNet2:Listen('colorsend')
rgbstuff(function(updatedRGBValues)

		updatePixels(updatedRGBValues)
	
end)

but then i get 2 errors in the module:
15:35.715 ReplicatedStorage.FastNet2.Server.Process:41: table index is nil - Server - Process:41
ReplicatedStorage.FastNet2.Client:50: invalid argument #2 to ā€˜formatā€™ (string expected, got nil) - Client - Client:50

or did i connect it wrong in my end part?

u need to create a identifier first then you can use the functional like this:

local FastNet2 = require("path.to.module")
local Remote1 = FastNet2.new("IdentiferName") -- this create new connection with spesific identifier

-- the usages, example:
Remote1:Listen(function(action: string, arg1, arg2)
-- logics?
if action == "work" then
print(arg1, arg2)
end
end)
Remote1:Fire(anything here sent to server)

-- note: the code is for client side, for server side is bit different.

you can also read the FastNet2 documentation site for more informations.

Link to Documentation site

i noticed ā€˜fireā€™ is only for the client and ā€˜firesā€™ is for the server so Iā€™ve
used it, I could of looked more into the documentation since im pretty stupid but anyways, but now its sending stuff in loops but errors with 2 errors: 16:49:09.894 ReplicatedStorage.FastNet2.Client:177: attempt to index nil with ā€˜Reliableā€™ - Client
ReplicatedStorage.FastNet2.Client:50: invalid argument #2 to ā€˜formatā€™ (string expected, got nil) - Client - Client:50

it appears to be in the client folder in this part of your module code and for the other err:

local function OnClientReceive(packets: any, secondPackets: any)
	if packets or secondPackets then
		if typeof(packets) == "table" then
			for Identifier, packet in packets do
				if Collections[Identifier] and Collections[Identifier].Connected then
					for _, data in packet do
						FastSpawn(Collections[Identifier].func :: any, table.unpack(data))
					end
				elseif Collections[Identifier].Reliable then -- error message lured me to here
					-- throw to Process as pre-process
					Process._pre(Identifier, packet)
				end
			end

try change to
FastNet2.new(ā€˜colorsendā€™, false)

tried that, same err:ReplicatedStorage.FastNet2.Client:50: invalid argument #2 to ā€˜formatā€™ (string expected, got nil) - Client - Client:50

question, does the module support tables with random numbers in it like :[[12,12,23],[12,12,23],[8,8,19],[4,4,15],[11,11,22],[11,11,22],[10,10,21],[11,11,22],[11,11,22],[11,11,22],[12,12,23],[12,12,23],[9,9,20],[11,11,22],[10,10,21],[10,10,21],[11,11,22],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,12,23],[12,8,17],[12,7,15],[12,12,22],[10,10,21],[11,11,22],[10,10,21],[9,9,20],[10,10,21],[10,10,21],[10,10,21],[11,11,23],[12,12,23],[11,11,22],[10,10,21],[11,11,22],[10,10,21],[12,12,23],[11,11,22],[9,9,20],[10,10,21], then that bit gets decoded from lists into tables.

also i removed the framerate bit since it waits unnecessary heres the code

local function RequestRGBValues(url)
	local success, response = pcall(http_GetAsync, HttpService, url)
	if not success or not response then return end
	local decode = http_JSONDecode(HttpService, response)
	return decode
end

local rgbvalues = FastNet2.new('colorsend', false)

print(FastNet2.CheckUpdate())

wrap(function()
	while true do
		local RGBValues
		repeat
			RGBValues = RequestRGBValues(_G.URL)
			
		until RGBValues
	
	       rgbvalues:Fires(RGBValues)

		
	
	
		end
end)


also i cached the http stuff for better peformance

what is RGBValues value have? can u print it

interesting, i might aswell try that but that rickroll vid was ran with remoteevents, ill give it a try

like i said, if it works ill do come comparisons on it, including with ngrok in game

It has no errors! but in my main where its tryna connect the function to update pixels it errors with ā€˜attempted to call a table valueā€™ since its not a issue with the module ill fix it

is this how i connect it since its not showing any colours in the screen but no errors in the module:

local rgbstuff = FastNet.Client('colorsend')  --assuming client auto connects to that server thingy if theres no server instance then it will create



rgbstuff:Connect(function(updatedRGBValues)

		updatecolor(updatedRGBValues)
	
end)

also i might aswell specify it as false for the reliable event thingy when firing

also i might aswell use the module in a another game i made which controls a bot in roblox with a screen to show my spare pcs screen since the keys and game id sending are very delayed so that game might be a good candidate.

u need to initialize on server every you creating new event on client so it dont stuck waiting server.

it still doesnt work when i added a wait statement so instead i added a print statement to the client thingy and this printed out: {
[ā€œfnā€] = {},
[ā€œidā€] = ā€œā€
}

and i stored the client bit on a while true do loop to see if it works.

No unreliable events with this version?

can u show how u initialize the event on server side

local rgbvalues = FastNet2.Server('colorsend')

wrap(function()
	while true do
		local RGBValues
		repeat
			RGBValues = RequestRGBValues(_G.URL)
	
		until RGBValues

		

	       rgbvalues:Fires(RGBValues)

		
	
	
		end
end)


client side:

	
local rgbstuff = FastNet2.Client('colorsend')

	task.wait()

rgbstuff:Connect(function(updatedRGBValues)
		
		updatecolor(updatedRGBValues)
	
	end)
	

try print this on :Connect line (client).

migrate to Warp

FastNet2 is officially discontinued but contribution still acceptable.

2 Likes