NetworkObject | A light-weight network module usable for everyone!

Not supported anymore. Use the modern version, BridgeNet

NetworkObject

An extremely light-weight, easy-to-use, abstraction/wrapper for networking!


NetworkObject is primarily an abstraction that lets you take away the annoyances of RemoteEvents. It provides a very easy API that minimizes the separations between server and client. Both the server and the client utilize the same functions, so there’s no looking if the script runs on the client, or the server!

Alongside having a very easy-to-use API, it’s also usable for everyone. It doesn’t matter how you like to structure your code, because the API acts as if it’s a reference to a remote event. You could put a constructor at the top of your script, and act as if it’s a normal RemoteEvent with a different API. You could put it into an object, and use it for composition.

The main benefit of using this module, though, isn’t the abstraction, or the easy-to-use API. It’s the timed connections! This simply means that synchronize the time that connections / fires go through the RemoteEvents. I do this for quite a few reasons.

Example Use

local NetworkObject = require(path.to.NetworkObject)

local Hello = NetworkObject.new("HelloWorld")

Hello:Connect(function()
     print("Hello World!")
end)

Hello:Fire()

Link to Script:


API

NetworkObject.new(name, yields, timeout)
Creates a new NetworkObject.

Name: The name of the RemoteEvent
Timeout (Client only): Timeout for :WaitForChild().

Returns: NetworkObject


NetworkObject:Fire(plrOrAll, ...)
Fires the RemoteEvent within the NetworkObject.

plrOrAll (Server only): If the parameter is a PlayerInstance, it will fire to the specified client. If it’s a string with the text “all”, it will fire to all clients.

Returns: nil


NetworkObject:Connect(function)
Connects to the RemoteEvent within the NetworkObject.

Function: Connects to the RemoteEvent. Passes in specified arguments, and also a PlayerInstance if it’s on the server.

Returns: Connection


NetworkObject:Destroy()
Destroys the NetworkObject.

No parameters.

Returns: nil


Roadmap

I aim to update this module often! There will be lots of new features coming, such as:

  • Rewrite it to use separate client/server functions that are set when .new() is called
  • Configuration to enable/disable certain aspects like instance caching
  • Format checking
  • Rate limiting
  • Returning promises
  • Authors for server-scripts

Done:

  • Instance caching
  • Timed connections

If you use this for any of your projects, by all means reply to this thread! It means a lot to me. If you find any bugs, please let me know. This is my personal networking module, so I update it often.

10 Likes

Very cool, seems useful, that said i didn’t understand the timed connections thing very well, how do i configure it and what exactly does it do?

Oops- left that unused code in there. Configurations don’t work right now.

Timed connections just make your connections / calls happen at Heartbeat.

1 Like

I see, does this also prevent RemoteEvents from triggering multiple times per call?

Not sure what you mean on that one. All it does is empty a queue into a RemoteEvent every Heartbeat- if there’s nothing in the queue, the remote isn’t called.

1 Like

Hello again! I finally got around to using this module but I had a question, what does the yields parameter in NetworkObject.new() do?

So those are client-only. If the RemoteEvent that it’s connected to doesn’t exist yet, it’ll wait (timeout) time until yielding/erroring

Sorry for the somewhat late reply! Also I updated it- you should probably grab the most recent version.

1 Like