Pike v8.1 release 6

Method Protocols.SocketIO.Universe()->farm()


Method farm

Client farm(.WebSocket.Request req, void|mapping options)

Parameter options

Optional options to override the defaults. This parameter is passed down as is to the underlying EngineIO.Socket.

Example

Sample minimal implementation of a SocketIO server farm:

Protocols.SocketIO.Universe myuniverse;

mixed echo(mixed id, function sendack, string namespace, string event,
 mixed ... data) {
  id->emit(event, @data);
  if (sendack)
    sendack("Ack","me","harder");
}

void wsrequest(array(string) protocols, object req) {
  httprequest(req);
}

void httprequest(object req) {
  switch (req.not_query) {
    case "/socket.io/":
      Protocols.SocketIO.Client client = myuniverse.farm(req);
      if (client)
        client->emit("Hello world!");
      break;
  }
}

int main(int argc, array(string) argv) {
  myuniverse = Protocols.SocketIO.Universe(); // Create universe
  myuniverse.register("", echo); // Register root namespace
  Protocols.WebSocket.Port(httprequest, wsrequest, 80);
  return -1;
}
See also

EngineIO.farm()