Handler Tutorial

Allows you to handle socket messages and responses
Unsplashed background img 1

This is a quick guide on Function Socket Handlers and Response Handlers. Handlers are used to handle messages to function sockets as well as responses to write to socket messages.

Handlers are actually quite simple. First off, you open the function socket:

open function socket at port 12345 with password "totallysafe" through function "Handler"

Or you write the message:

write "totallysafe", "some value" to socket with host "host.com" port 12345 to handle response through function "Handler" with id "someid

Then (probably beforehand) you create the function:

function Handler(args: strings, info: objects):
  do stuff

You can send a message back to whoever sent the message. If the handler is handling a message received from a function socket, then you can simply do

return "response"

In this case, the function must be instead written as

function Handler(args: strings, info: objects):: strings:

If the message received is a response to a socket write effect, the you have to do

write "totallysafe", "response" to socket with host {_info::2} port {_info::3} to handle response through function "Handler" with id "anotherid" You'll notice that we are using some arguments in our socket write effect, that's because we want to write to the same host/port that sent the response, and those arguments specify the host/port.

Here's a run-down of what each argument is:

{_args::*}

is a list variable containing the messages received.

{_info::*}

is a list variable containing extra information about the messages.

{_info::1}

depends on what kind of message the Handler is handling. If this is handling a message from a server received through a function socket, then it is the port that the message was received from. If this is handling the response to a socket write message, then it is the id specified in the socket write effect.

{_info::2}

is either the hostname or IP of the client that sent the messages.

{_info::3}

is the port from which the client sent the messages.

All Handlers must be formatted this way, (They can have a different function name and argument names of course,) but which arguments you actually do anything with is up to you.

That's it!