Packet - Networking library

I just loved this update, thx! table support is fire

Never mind, this is apparently global and now errors for every single event regarding of what arguments being given, I don’t know why.

This didn’t happen before, if it matters, It started happening after I fully assigned each script that will use the Packet, but I didn’t give it types expect for the main script that created the packet.

If you like you can dm me your project and ill take a look at it

Destroy doesn’t seem to exist but you listed it in the functions ?

friggin packet yo. alr but seriously suphi your content is honeslty so helpfull in unexpected ways and your channel is honeslty kinda underrated

I have some problem in this topic

I’ll give this module a try before I continue to work on my own Network library seems like this would fix all my issues and needs.

Buffers types appear to break after a certain size. For example:

Packet script

--!strict

local Packet = require("./Packet")

local p = {
	IncCounter = Packet("Counter", Packet.Nil):Response(Packet.NumberF64),
	YugeBuffer = Packet("Buffer", Packet.NumberU32):Response(Packet.Buffer)
}

-- here would be any limits

return p

Server script

local Packet = require("../ReplicatedStorage/Packet")
local Packets = require("../ReplicatedStorage/Packets")

local counter = 0
local SIZE = 32

Packets.IncCounter.OnServerInvoke = function(player)
	counter += 1
	print(`Server count {counter}`)
	return counter
end

function dummyBuffer(size: number?): buffer
	size = if size then size else SIZE
	local b = buffer.create(size)
	
	for i = 1, size do
		buffer.writeu8(b, i - 1, math.random(0, 255))
	end
	
	return b
end

Packets.YugeBuffer.OnServerInvoke = function(player, size)
	local buff = dummyBuffer(size)
	print(`Buff size before send: {buffer.len(buff)}`)
	
	return buff
end

Client script

local Packet = require("../ReplicatedStorage/Packet")
local Packets = require("../ReplicatedStorage/Packets")

local SIZE = 32
local s = SIZE

while true do
	task.wait(1)
	print(`Trying buffer size of {s} bytes`)
	local b = Packets.YugeBuffer:Fire(s)
	print(`After receive: {buffer.len(b)}`)
	s += SIZE
end

Here’s the console output:

Is it possible for you to implement a way to break down large buffers in the library to send int chunks, or must we roll it ourselves?

You can modify or make a new buffer type if you want to have a length longer then 255 the same is true for strings

its reasonably simple to do
this is a buffer that only supports 255

types.Buffer = ("Buffer" :: any) :: buffer
reads.Buffer = function() return ReadBuffer(ReadU8()) end
writes.Buffer = function(value: buffer) local length = buffer.len(value) Allocate(1 + length) WriteU8(length) WriteBuffer(value) end

here is a buffer type that supports a max length of 65535

types.BigBuffer = ("BigBuffer" :: any) :: buffer
reads.BigBuffer = function() return ReadBuffer(ReadU16()) end
writes.BigBuffer = function(value: buffer) local length = buffer.len(value) Allocate(2 + length) WriteU16(length) WriteBuffer(value) end

but this buffer uses 2 bytes instead of 1 to store the length

Found a bug where if you try to fire the same packet twice in a frame it’ll drop ALL packets and not fire anything.

Any work-arounds?

if _nemesisDialog then
	_clientReplicate:FireClient(_playerEverKilled, "a4a_doMessage", {_nemesisDialog})
	_clientReplicate:FireClient(Player, "a4a_doMessage", {_nemesisDialog})
	_clientReplicate:FireClient(Player, "a4a_doMessage", {_otherNemesisString, "killstreak"})
	_clientReplicate:FireClient(_playerEverKilled, "a4a_doMessage", {_nemesisString, "nemesis"})
	print(true, 18, _nemesisDialog)
end

I’m not experiencing the same problem would you mind sharing a project with the problem your experiencing

here is my project I used to test Test.rbxl (70.4 KB)

also error messages and showing how you defined your types can help

There aren’t any error messages and the thread still goes on. I also tried to reduce the amounts of packets firing but still nothing happens. Other events seem to fire fine.



I tried debugging the method.
image

Other events also seem to fire fine expect the ones I listed.
image

Incredible post! I’ve honestly never used packets in my projects before, and I’m new to scripting. The fact that something like this is open sourced with a provided tutorial, you’re doing beautiful things. Keep up the good work Suphi!

how did you define the packets that are not working and what types are you sending?

The packet is defined normally in the same script that had the working the same packet, I’m only using ONE packet, it works normally in other scripts including the same one I’m having issues in, but the snippet I posted refuses to send calls to the client.
The types I’m sending are all strings.

local _clientReplicate = _clientReplicator("_replicateEffects", _clientReplicator.String, {_clientReplicator.Any}) 

if you like you can DM me the project file so I can test it maybe be able to find the problem