Module Network

Used on the client side to communicate with a server

Info:

  • Release: 0.0.1
  • Author: Will

Functions

connect (ip, port) Connect to the server at ip:port.
on (cmd, callback) Used to set callbacks which are called when the server sends a certain command
send (cmd, params) Send a message to the server, it will be passed to clients
instantiate (t, properties) instantiate an object accross the server.
destroy (id) Send a destroy command to the server.
update () Update the network.
close () Gracefully exit from the server, telling it that this player has left If this function is not called, the server will think this player is still connected
Deserialize (ser) Deserialize a string from the server by running the string and returning the result
log (str) Print to the command line and log to a file

Tables

Network Stores network variables and callbacks


Functions

connect (ip, port)
Connect to the server at ip:port. First function to be called once network is created

Parameters:

  • ip string IP address of the server
  • port number Port to connect to
on (cmd, callback)
Used to set callbacks which are called when the server sends a certain command

Parameters:

  • cmd string The command to listen for. Ex: 'update'
  • callback function The function called when this command arrives
send (cmd, params)
Send a message to the server, it will be passed to clients

Parameters:

  • cmd string The command to send. This should be the same as the listener on the server side
  • params table Parameters to send to the listeners. It will be serialized to a string and deserialized later
instantiate (t, properties)
instantiate an object accross the server. This needs to be implemented by the user

Parameters:

  • t The type of object to instantiate
  • properties table Properties to spawn object with
destroy (id)
Send a destroy command to the server. Listener needs to be implemented by client

Parameters:

  • id number ID of object to destroy
update ()
Update the network. Loops through all messages (max of 500 per update), handling them by calling their callbacks

Returns:

    number -1 if a timeout error occurred, or nil
close ()
Gracefully exit from the server, telling it that this player has left If this function is not called, the server will think this player is still connected
Deserialize (ser)
Deserialize a string from the server by running the string and returning the result

Parameters:

  • ser string The string to be deserialized
log (str)
Print to the command line and log to a file

Parameters:

  • str string The string to log

Tables

Network
Stores network variables and callbacks

Fields:

  • udp The interface with the server
  • callbacks A table filled with callbacks that the user creates
  • id The ID assigned to this client by the server
  • sendrate How often to send updates to the server
generated by LDoc 1.4.3 Last updated 2016-04-04 22:06:14