Lua Class - networking

networking is a class in the Teverse Lua API that contains 3 properties, 6 methods and 8 events.

This class cannot be constructed, it is managed by Teverse.

Properties
READONLY
table clients

A readonly list of clients, excluding local client when offline

CODE SAMPLE
print(networking.clients) --> {}
READONLY
boolean isConnected

True when a connection is established

CODE SAMPLE
print(networking.isConnected) --> true
READONLY
client localClient

The current local client, nil when unauthenticated

CODE SAMPLE
print(networking.localClient) --> client
Methods
broadcast( string eventName , ... )

Reliably sends the information you pass to all direct connections. Note that a client cannot broadcast to other clients as they are not directly connected.

CODE SAMPLE
networking:broadcast("", ...) --> 
client getClient( string nameOrClientId )

Returns the client for the matching name or id you provide

CODE SAMPLE
networking:getClient("") --> client
netStats getStats( )

Internal use

CODE SAMPLE
networking:getStats() --> netStats
initiate( string appId )

Initiate a networked app

CODE SAMPLE
networking:initiate("") --> 
sendToClient( client client , string eventName , ... )

[SERVER ONLY] Reliably sends the information you pass

CODE SAMPLE
networking:sendToClient(client, "", ...) --> 
sendToServer( string eventName , ... )

This is an alias for broadcast that only works on the client side.

CODE SAMPLE
networking:sendToServer("", ...) --> 
Events
:on("_clientConnected", function( client user ) end)

Fired when a user connects

CODE SAMPLE
networking:on("_clientConnected", function(user)
  print(user) --> client
end)
:on("_clientDisconnected", function( client user ) end)

Fired when a user disconnects

CODE SAMPLE
networking:on("_clientDisconnected", function(user)
  print(user) --> client
end)
:on("_connected", function( ) end)

Fired when a connection has started

CODE SAMPLE
networking:on("_connected", function()

end)
:on("_disconnected", function( ) end)

Fired when a connection fails or stops

CODE SAMPLE
networking:on("_disconnected", function()

end)
:on("_downloadProgress", function( string percentage ) end)

Fired when an update progresses

CODE SAMPLE
networking:on("_downloadProgress", function(percentage)
  print(percentage) --> ""
end)
:on("_localAuthenticating", function( string status ) end)

Fired when the local user authenticates

CODE SAMPLE
networking:on("_localAuthenticating", function(status)
  print(status) --> ""
end)
:on("_update", function( string message ) end)

Fired when an update begins

CODE SAMPLE
networking:on("_update", function(message)
  print(message) --> ""
end)
:on("changed", function( string property, variant oldValue, variant newValue ) end)

Fired when a property is changed.

CODE SAMPLE
networking:on("changed", function(property, oldValue, newValue)
  print(property) --> ""  print(oldValue) --> variant  print(newValue) --> variant
end)

Some sections of our docs are maintained on github.