Difference between revisions of "Unite Client Method list"
(Created page with "__NOTOC__ = Gideros Unite Framework = == Client Method list == === Constructor === '''Method name''' new(config) '''Description''' Create client instance '''Input parameter...") |
|||
Line 119: | Line 119: | ||
serverlink:close() | serverlink:close() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | {|- | ||
+ | |style="width: 50%;"| | ||
+ | :::::::::::: | ||
+ | '''[[Unite Server Method list]]''' | ||
+ | |||
+ | |style="width: 50%;"| | ||
+ | :::::::::::: | ||
+ | '''[[Unite Server Event list]]''' | ||
+ | |} | ||
+ | |||
+ | {|- | ||
+ | |style="width: 50%;"| | ||
+ | :::::::::::: | ||
+ | '''[[Unite Client Method list]]''' | ||
+ | |||
+ | |style="width: 50%;"| | ||
+ | :::::::::::: | ||
+ | '''[[Unite Client Event list]]''' | ||
+ | |} | ||
Revision as of 06:32, 14 December 2023
Gideros Unite Framework
Client Method list
Constructor
Method name new(config)
Description Create client instance
Input parameters table config - lua table with configuration options:
- string username - username to display on devices (default: hostname or device's IP address)
- string ip - ip address to use for server (default: current device's IP address)
- int tcpPort - port to use for tcp connection (default: 5883)
- int udpPort - port to use for udp connection (default: 5884)
- int discoveryPort - port to use for device discovery (default: 5885)
- int multicast - multicast ip address for device discovery (default: 239.192.1.1)
- int serverIP - ip address of server, if no discovery needed and can connect tp server directly (default: nil)
- string connectionType - which connection protocol to use tcp, udp or both (default: 'both')
Example
local serverlink = Client.new({
username = "ar2rsawseen",
ip = nil,
port = 15000,
multicast = "239.192.1.1",
serverIP = nil,
connectionType = "tcp"
})
Start Listening
Method name startListening()
Description Start Listening to server, both when server is broadcasting/multicasting for discovery, or when client is already connected to server (for example, by providing it's ip address)
Stop Listening
Method name stopListening()
Description Stop Listening to server, both when server is broadcasting/multicasting for discovery, or when client is already connected to server
Connect to specified Server
Method name connect(id)
Description When server is broadcasting/multicasting, if client is not yet connected to any server, it recieves new server events with server ID. You need to provide that ID to connect method, to connect to specified server
Input parameters int id - server id received from new server event
Example
serverlink:connect(111222333)
Add Method
Method name addMethod(name, method, scope)
Description Add method which can be called through the network by other devices
Input parameters Input parameters are similar to adding new event listener
string name - name of command to associate with this method, could be simply method name as string
function method - method that will be called from other connected devices. This function will be called by other devices, and all parameters provided by other devices will be passed to this function. Additionally, the last providd parameter will be the source of message - id of device from which message originated
object scope - scope to use for method, if for example using class method and not simple function, you can provide self variable if defined inside class, of class instance if defiend outside class (default: nil)
Example
serverlink:addMethod("draw", self.draw, self)
Call Method
Method name callMethod(...)
Description Call specific method for all connected devices
Input parameters string command - name of command, to call the method associated with this command
Other parameters can be any values, that will be passed to called method
Example
serverlink:callMethod("draw", 100, 200)
Call Method of specific device
Method name callMethodOf(...)
Description Call specific method for specific connected devices
Input parameters string command - name of command, to call the method associated with this command
Other parameters can be any values, that will be passed to called method
Last parameter should be the ID of device, to which to send command
Example
serverlink:callMethodOff("draw", 100, 200, 111222333)
Get devices
Method name getDevices()
Description Get ID of all devices connected to server. Due to limitation, that ID's of devices are retrieved through sockets on the network, this method does not return list of devices, but rather generates multiple "device" events, one for each connected device
Example
serverlink:getDevices()
Close Client
Method name close()
Description Closes the client, disconnects it from server, disabled listening and erases ID. Serves as destructor for the class
Example
serverlink:close()
|
|
|
|