Server Communication Tutorial

Allow multiple servers to communicate with each other
Unsplashed background img 1

This is a simple tutorial showing you how you can use sockets to communicate with another server.

First, both servers need to have MundoSK.

Next, you need to open a function socket on one of the servers.

open function socket at port %integer% with password "awesomepassword" through function "Handler"

Make sure both servers know each others' password.

Now you need the handler. For the full details on how to write the handlers see the Handlers tutorial, here we'll just put the finished one here:

Function Socket Handler:

function Handler(args: strings, info: objects):
  do stuff
  set {_value} to something
  return {_value}

Response Handler:

function ResponseHandler(args: strings, info: objects):
  do stuff
  set {_value} to something
  write "awesomepassword", {_value} to socket with host "other server's ip" port %integer% to handle response through function "ResponseHandler" with id "someid"

The important part here is that last line, that writes back to the server after handling the response.

Now, to get it started, the server that writes the messages and has the Response Handler has to run that last line seperately to get it started:

write "awesomepassword", "some value" to socket with host "other server's ip" port %integer% to handle response through function "ResponseHandler with id "someid"

Once that happens, the server with the function socket open handles the message through the Function Handler Socket and sreturns a response, which is when the Response Handler handles the response and sends a new message, repeating the cycle.

And that's it! What you do can go far beyond that, doing many different things, opening function sockets on both servers.