Table of Contents
The example below shows a simple server for a service called "echo"
that provides a single function named
echo
.
This function accepts an argument, and responds with a copy of the request.
#include <err.h> #include <stdlib.h> #include <string.h> #include <ipc.h> /* Take a line of input and copy it to the output */ char * echo(const char *input) { return (strdup(input)); } int main(int argc, char *argv[]) { int result; result = ipc_server_main(IPC_DOMAIN_USER, "echo"); if (result < 0) errx(1, "ipc_server_main: %s", ipc_strerror(rv)); exit(EXIT_SUCCESS); }
The ipc_server_main
starts an IPC server for the local user, and binds to the "echo" service.
It will run in a loop servicing client requests.