Server Molecule
From oWiki
Contents |
Preference Dialog
Attributes
type
string ( r )
Type of this molecule, 'server'.
pref.name
string ( r )
The scriptable name for this molecule. This name can be set using rename method dynamically.
pref.enableWhen
string ( r, w )
Specifies the event that activates this molecule. Default is 'none'.
pref.disableWhen
string ( r, w )
Specifies the event that deactivates this molecule. Default is 'none'.
pref.port
int ( r, w )
Specifies the port number which the server listens to.
pref.scriptName
string ( r, w )
Specifies the name of the script molecule to receive socket events.
Methods
rename(n)
n: string
| Rename this molecule. |
clone()
Return: a molecule
| Create a clone of this molecule. |
attach(droplet)
droplet: a droplet object (e.g. app.box.droplet)
| Attach this molecule to a droplet. |
detach()
| Remove this molecule from its droplet. |
deleteMod()
| Delete this molecule. |
serialize()
Return: string
| Serialize this molecule into its JSON representation. |
start()
| Starts the server. |
stop()
| Stops the server. |
sendData( peer, data )
peer: string
data: string
| Send data to peer who is currently holding an active connection with the server. The parameter 'peer' is the nickname of the member who initiated this connection. |
readData( peer )
peer: string
Return: string
| Read data from the connection with the given peer. |
disconnect( peer )
peer: string
| Drop the connection with the given peer. |
Comments
The Server sends 3 different types of socket events to the script molecule during the life of a connection. These events are passed to the script molecule via the input parameter, 'params'.
params.type: type of event (see below for possible values).
params.peer: nickname of the peer.
params.dataLength: length of the incoming data.
| params.type | Description |
|---|---|
| onAccept | The server just accepted a connection request. The params.peer contains the nickname of the member who initiated the connection. |
| onDataAvailable | Data just arrived from the connection with params.peer. The amount of data available is params.dataLength. Data can be read using readData(params.peer). |
| onDisconnect | Server detects the disconnection of params.peer. There may still be some data available for read. |
On connection, the Server Molecule sends out a banner to identify itself. This banner includes the following information:
oTakhi Server <port> CRLF
Server Name: server_name CRLF
Server Path: file_path CRLF
Session Owner: session_owner CRLF
Time Stamp: timestamp CRLF CRLF
server_name: The name of the server molecule.
file_path: The CCRX URL of the app conaining this server molecule.
session_owner: The nickname of the member currently running this app.
timestamp: The last_modified timestamp of this document.

